From: Ardis Lu Date: Wed, 6 Aug 2025 05:03:53 +0000 (-0700) Subject: Cleanup unnecessary code X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=f7bc249d711a137ec2cc68e213c36d0354662a25;p=static-encrypt-passkey Cleanup unnecessary code --- diff --git a/index.html b/index.html index 99dd3a7..20a1de3 100644 --- a/index.html +++ b/index.html @@ -51,16 +51,14 @@ 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; }); diff --git a/script.js b/script.js index 8a9a40d..ac6eb54 100644 --- 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 },