From: Ardis Lu Date: Sat, 25 Feb 2023 04:14:38 +0000 (-0800) Subject: Don't hardcode array size X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=49088b5f59307f60192e659e2347becd6b6e03f2;p=static-encrypt Don't hardcode array size --- 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',