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>
// 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.
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 },