otp_crypto/encryptor library
Encryptor – Builds SecureMessage (headers+body) from plaintext
High-level symmetric encryption orchestrator:
- Derive {encKey, macKey} via HKDF-SHA256 from the singleton config.
- Compute current time window
w. - Generate 8-byte random nonce
n. - Derive IV = HMAC(macKey, "iv" || u64be(w) || n)
:16. - Encrypt plaintext with AES-256-CBC + PKCS#7 using encKey+IV →
c. - Compute tag = HMAC(macKey, "tag" || u64be(w) || n || c).
- Produce
SecureMessage { v,w,n,c,tag }.
This class does not send HTTP. It only returns a SecureMessage.
To serialize into headers/body, use ApiClient.toWire(msg).
SECURITY NOTES:
- HKDF keys are derived once per
Encryptorinstance and cached. - Always verify on the recipient before decryption (Encrypt-then-MAC).
- IV is never transmitted; both sides recompute it.
HINTS:
- You may keep a single
Encryptoraround (stateless w.r.t. requests). - Provide your own
NonceGeneratorin tests for determinism.