From 49088b5f59307f60192e659e2347becd6b6e03f2 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Fri, 24 Feb 2023 20:14:38 -0800 Subject: [PATCH] Don't hardcode array size --- decrypt.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/decrypt.js b/decrypt.js index cfa0606..9b5dd54 100644 --- a/decrypt.js +++ b/decrypt.js @@ -4,10 +4,10 @@ export default async function decrypt(content, password) { const contentBuffer = Uint8Array.from(atob(content), c => c.charCodeAt(0)); const salt = new Uint8Array(32); const iv = new Uint8Array(12); - const ciphertext = new Uint8Array(contentBuffer.byteLength - 44); - salt.set(contentBuffer.slice(0, 32)); - iv.set(contentBuffer.slice(32, 44)); - ciphertext.set(contentBuffer.slice(44)); + const ciphertext = new Uint8Array(contentBuffer.byteLength - salt.byteLength - iv.byteLength); + salt.set(contentBuffer.slice(0, salt.byteLength)); + iv.set(contentBuffer.slice(salt.byteLength, salt.byteLength + iv.byteLength)); + ciphertext.set(contentBuffer.slice(salt.byteLength + iv.byteLength)); const keyMaterial = await crypto.subtle.importKey( 'raw', -- 2.47.3