* @returns {Promise<string>} A promise that resolves to the plaintext.
*/
export default async function decrypt(content, password) {
- const encodedPassword = new TextEncoder().encode(password);
+ const encoder = new TextEncoder();
+ const encodedPassword = encoder.encode(password);
+ const additionalData = encoder.encode('https://github.com/ardislu/static-encrypt');
const contentBuffer = Uint8Array.from(atob(content), c => c.charCodeAt(0));
const salt = new Uint8Array(32);
);
const encodedPlaintext = new Uint8Array(await crypto.subtle.decrypt(
- { name: 'AES-GCM', iv },
+ { name: 'AES-GCM', iv, additionalData },
key,
ciphertext
));
const encoder = new TextEncoder();
const encodedPlaintext = encoder.encode(plaintext);
const encodedPassword = encoder.encode(password);
+ const additionalData = encoder.encode('https://github.com/ardislu/static-encrypt');
const salt = new Uint8Array(32);
const iv = new Uint8Array(12);
);
const ciphertext = new Uint8Array(await crypto.subtle.encrypt(
- { name: 'AES-GCM', iv },
+ { name: 'AES-GCM', iv, additionalData },
key,
encodedPlaintext
));