The Key Your Own Code Is Not Allowed to Read
Subtitle: A key can be usable without being readable.
- THE BOUNDARY - HAND WORK ACROSS:
- crypto.subtle returns Promises
- Work may leave the JavaScript thread
- CryptoKey is a handle, not raw bytes
- Secure contexts only; plain HTTP refuses
- NON-EXTRACTABLE - WHAT IT MEANS:
- Set extractable to false at creation
- sign, verify, encrypt, decrypt still work
- exportKey rejects every raw-byte request
- Stolen script may spend, not steal, the key
- FALSIFY THE COMFORT:
- Hidden bytes do not mean safe use
- Injected script can sign while the page lives
- Client code cannot be a trust boundary
- No bcrypt, Argon2, or scrypt lives here
- Password checks belong off the client
- HONEST TEST + ONE EXCEPTION:
- Generate a non-extractable key
- Sign a message: success
- Call exportKey: rejection
- Those two results are the security model
- getRandomValues is sync and outside subtle
- Never replace it with Math.random
