JSFiddle - React, Tailwind, and code Playground
by Weston Ruter
JavaScript
const ptUtf8 = new TextEncoder().encode('my plaintext');
const pwUtf8 = new TextEncoder().encode('my password');
const pwHash = await crypto.subtle.digest('SHA-256', pwUtf8);
const iv = crypto.getRandomValues(new Uint8Array(12));
const alg = { name: 'AES-GCM', iv: iv };
const key = await crypto.subtle.importKey('raw', pwHash, alg, false, ['encrypt']);
crypto.subtle.encrypt(alg, key, ptUtf8).then( function() {
console.info(...arguments);
});