Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: properly calculate data length when encrypting

thecodrr7be5e115e96b
diff --git a/apps/web/public/crypto.worker.js b/apps/web/public/crypto.worker.js
index 8ee9745cd..0b2b320ff 100644
--- a/apps/web/public/crypto.worker.js
+++ b/apps/web/public/crypto.worker.js
@@ -1,6 +1,7 @@
/* eslint-disable */
var context;
+const enc = new TextEncoder();
if (!self.document) {
self.addEventListener("message", onMessage);
}
@@ -107,8 +108,9 @@ const encrypt = (passwordOrKey, data) => {
const nonce = sodium.randombytes_buf(
sodium.crypto_aead_xchacha20poly1305_ietf_NPUBBYTES
);
+ const dataArray = enc.encode(data);
const cipher = sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(
- data,
+ dataArray,
undefined,
undefined,
nonce,
@@ -122,7 +124,7 @@ const encrypt = (passwordOrKey, data) => {
cipher,
iv,
salt,
- length: data.length,
+ length: dataArray.length,
};
};