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
window. - Generate 8-byte random nonce
nonce. - Derive IV = HMAC(macKey, "iv" || u64be(window) || nonce)
:16. - Encrypt plaintext with AES-256-CBC + PKCS#7 using encKey+IV →
ciphertext. - Compute tag = HMAC(macKey, "tag" || u64be(window) || nonce || ciphertext).
- Produce
SecureMessage { version, window, nonce, ciphertext, 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.