Security
encrypted secrets
ChaCha20-Poly1305 AEAD with CSPRNG and DPAPI
how it works
API keys in config are never stored as plaintext. the encryption pipeline:
- key generation — 256-bit key from OS CSPRNG (not UUID)
- encryption — ChaCha20-Poly1305 AEAD with fresh random nonce per operation
- integrity — Poly1305 MAC tag prevents tampering
- storage — encrypted values stored with
enc2:prefix in config.toml - key protection — secret key file at
~/.baihu/.secret_keywith 0600 permissions
windows DPAPI
on windows, the secret key file itself is envelope-encrypted with DPAPI, bound to your windows login session. even if someone reads the file, they get ciphertext that only decrypts under your user account.
zeroize
key material is wrapped in Zeroizing<Vec<u8>> so it's overwritten with zeros when dropped. no secret data lingers in memory after use.
legacy migration
secrets encrypted with the old XOR cipher (enc: prefix) are automatically migrated to ChaCha20 (enc2:) on decrypt. the old format is deprecated.
testing
cargo test --lib -- security::secrets