From 7be5e115e96b54aa22761a3dd9dfd4b6477dfc4a Mon Sep 17 00:00:00 2001 From: thecodrr Date: Thu, 10 Dec 2020 12:32:31 +0500 Subject: [PATCH] fix: properly calculate data length when encrypting --- apps/web/public/crypto.worker.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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, }; };