Expand description
Password-based encryption for built sites: AES-256-GCM + PBKDF2.
Pure (§2.1): no I/O, no filesystem. encrypt takes plaintext + password +
an injected rng and returns an EncryptedPayload; decrypt takes a
payload + password and returns the plaintext. The rng is injected so the
whole transform is deterministic given the rng’s output (testable, no global
randomness source).
The browser-side decryption uses the same algorithm via WebCrypto
(crypto.subtle.deriveKey + crypto.subtle.decrypt), so a payload encrypted
in Rust decrypts in the browser and vice versa (ADR-0012).
Structs§
- Encrypted
Payload - An encrypted payload: the ciphertext plus the salt and nonce needed to decrypt it (§1.2 — a represented state, not a bag of bytes).
Enums§
- Crypto
Error - Why decryption failed — the password was wrong, the payload is corrupt, or the base64 encoding is malformed.
Constants§
- PBKD
F2_ ITERATIONS - PBKDF2 iteration count — 600,000 with HMAC-SHA-256 (OWASP 2023 recommendation for PBKDF2-SHA256). The same literal appears in the decrypt shell’s inline JS so the browser-side WebCrypto derivation matches.
Functions§
- decrypt
- Decrypt an
EncryptedPayloadwithpassword. - encrypt
- Encrypt
plaintextwithpassword, usingrngto generate a fresh salt and nonce (§2.1 — pure w.r.t. rng: the rng is the only source of nondeterminism).