@raae
vs.
Thank you Jeffrey Goldberg!
@jpgoldberg on Twitter
jcy8BRD4&NidjK6zXBw<w1Jw#gqkmEwcRWev@@41D5H@9K}#>=)+Qw0,kVv}U6p
A long random sequence of characters has high entropy, a short human memorable password has low entropy.
const key = await window.crypto.subtle.generateKey(
{
name: "AES-GCM",
length: 256
},
true,
["encrypt", "decrypt"]
);AES-GCM
Advanced Encryption Standard
with Galois Counter Mode
const note = "A very secret note";
const noteBuffer = new TextEncoder("utf-8").encode(note);
const nonce = window.crypto.getRandomValues(new Uint8Array(12));
const cyphertext = await window.crypto.subtle.encrypt(
{
name: "AES-GCM",
iv: nonce
},
key,
noteBuffer
); const plaintext = await window.crypto.subtle.decrypt(
{
name: "AES-GCM",
iv: nonce
},
key,
cyphertext
);
const decoder = new TextDecoder("utf-8");
const decryptedNote = decoder.decode(new Uint8Array(plaintext));
console.log(decryptedNote); // A very secret note const password = "The user's secret password"
const enc = new TextEncoder();
const passwordAsKey = await window.crypto.subtle.importKey(
"raw",
enc.encode(password),
{name: "PBKDF2"},
false,
["deriveBits", "deriveKey"]
);PBKDF2
Password-Based Key Derivation Function 2
const salt = window.crypto.getRandomValues(new Uint8Array(12));
const key = await window.crypto.subtle.deriveKey(
{
name: "PBKDF2",
salt: salt,
iterations: 100000,
hash: "SHA-256"
},
passwordAsKey,
{ name: "AES-GCM", length: 256},
true,
[ "encrypt", "decrypt" ]
);
PBKDF2
Password-Based Key Derivation Function 2
with key
derivation
const keyPair = window.crypto.subtle.generateKey(
{
name: "RSA-OAEP",
modulusLength: 4096,
publicExponent: new Uint8Array([1, 0, 1]),
hash: "SHA-256"
},
true,
["encrypt", "decrypt"]
);RSA-OAEP
Rivest–Shamir–Adleman
Optimal Asymmetric Encryption Padding
Encryption
Decryption
Private key management
Decryption
@raae