]> git.ardis.lu - static-encrypt/commitdiff
Don't hardcode array size
authorArdis Lu <ardisglu@gmail.com>
Sat, 25 Feb 2023 04:14:38 +0000 (20:14 -0800)
committerArdis Lu <ardisglu@gmail.com>
Sat, 25 Feb 2023 04:14:38 +0000 (20:14 -0800)
decrypt.js

index cfa06066517cf4376aafb033a8b4aa84675ad402..9b5dd5454537a2d18d952d61b5c9ec5afabb97e6 100644 (file)
@@ -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',
This page took 0.039197 seconds and 4 git commands to generate.