The watch post’s tools: a SHA-256 fingerprint, an HMAC stamp and an AES-GCM box from the real crypto.subtle, keys that cannot be taken. An interactive Web…
Why it matters
Hashes are in download checks, ETags, Git, subresource integrity. HMAC signs webhooks, session cookies and tokens. AES-GCM encrypts data you need to read again. The wrong tool (a hash for passwords, base64 for a secret, an IV used twice) is a real security bug.
The key idea
A fingerprint has no key, a stamp has a key, a box has a key and a fresh IV
Common mistakes
Passwords hashed with plain SHA, and easy to guess SHA-256 is fast on purpose, and for passwords that is a weakness. For passwords use a slow, salted hash: PBKDF2 (crypto.subtle.deriveBits) with many iterations, or bcrypt/argon2 on the server, with a unique salt per user.
Thinking a hash can be decrypted back into its text A hash is one way and has no key: there is no "undigest". Data you need to read again is encrypted (AES-GCM) with a key; a hash is only for comparing.
It shows [object Promise], or crypto.subtle is missing on HTTP Every crypto.subtle method returns a Promise: use await. And crypto.subtle only exists in a secure context (https or localhost); on plain http it is undefined, so check window.isSecureContext first.
Try it in this playground
Change one letter of the parcel About half of the 256 bits change with it. No pattern.
Forge the neighbourhood head’s notice Change one word: verify answers false.
Ask the browser for the watch’s keyexportKey is refused: the key was made so it cannot be taken.
Open the box with another key The browser refuses with OperationError, rather than handing back wrong contents.