Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// Simple encryption with Web Crypto API async function encrypt(text, password) { const key = await deriveKey(password); const iv = crypto.getRandomValues(new Uint8Array(12)); const encoded = new TextEncoder().encode(text); const buf = await crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, encoded); return JSON.stringify({ iv: [...iv], data: [...new Uint8Array(buf)] }); } // Store encrypted const encrypted = await encrypt(sensitiveData, userPassword); localStorage.setItem("secure", encrypted); // Note: the password must come from the user — never hardcode it!
Result
Open