]> git.ardis.lu - static-encrypt-passkey/commitdiff
Cleanup unnecessary code
authorArdis Lu <ardisglu@gmail.com>
Wed, 6 Aug 2025 05:03:53 +0000 (22:03 -0700)
committerArdis Lu <ardisglu@gmail.com>
Wed, 6 Aug 2025 05:03:53 +0000 (22:03 -0700)
index.html
script.js

index 99dd3a7fd2388e7cf01d59a43221ac9d7a4a0f36..20a1de3376c58f404435963d7d8a83199c4ed6bf 100644 (file)
       const { content } = Object.fromEntries(new FormData(e.target));
       const { output } = e.target.elements;
       output.textContent = '';
-      let text;
       try {
         output.removeAttribute('data-error');
-        text = e.target.id === 'encrypt' ? await encrypt(content) : await decrypt(content);
+        output.textContent = e.target.id === 'encrypt' ? await encrypt(content) : await decrypt(content);
       }
       catch (error) {
         output.setAttribute('data-error', '');
-        text = error;
+        output.textContent = error;
       }
-      output.textContent = text;
     });
   </script>
 </body>
index 8a9a40d7aa598ab61e68d6d19b3fd6b9266e5da6..ac6eb54d9cffea6a90f95e2b4ad7fb2b55ea28fc 100644 (file)
--- a/script.js
+++ b/script.js
@@ -84,6 +84,7 @@ export async function encrypt(plaintext) {
   // Prepare non-crypto inputs
   const encoder = new TextEncoder();
   const encodedPlaintext = encoder.encode(plaintext);
+  const info = encoder.encode('https://github.com/ardislu/static-encrypt-passkey');
 
   // Pad ciphertext so the final buffer length is a multiple of 3, to remove base64 padding. Not cryptographically
   // significant, just for aesthetics. +16 assumes ciphertext includes a 128 bit AES-GCM authentication tag.
@@ -92,10 +93,7 @@ export async function encrypt(plaintext) {
   paddedPlaintext.set([p]); // Offset to discard on decode
   paddedPlaintext.set(encodedPlaintext, p); // Gap filled with zero bytes, e.g. [3, 0, 0, ...encodedPlaintext]
 
-  const info = encoder.encode('https://github.com/ardislu/static-encrypt-passkey');
-
   const prf = await createPrf();
-
   const key = await getKey(prf, salt, info);
   const ciphertext = new Uint8Array(await crypto.subtle.encrypt(
     { name: 'AES-GCM', iv },
This page took 0.052806 seconds and 4 git commands to generate.