Encrypting secrets at rest

Store third-party keys (like BYOK provider keys) encrypted — no dependency.

class=kw>from larz.crypto class=kw>import Cipher
c = Cipher(app_secret)          class=com># derive keys class=kw>from your app secret
token = c.encrypt("sk-secret")  class=com># store this in your DB
key   = c.decrypt(token)        class=com># -> "sk-secret", or None if tampered / wrong secret

The construction is a standard composition of standard-library primitives: separate encryption and MAC keys derived from your secret via HMAC-SHA256, a random 16-byte nonce per message, HMAC-SHA256 in counter mode as the keystream, and encrypt-then-MAC authentication. A tampered or wrong-key token decrypts to None.

This is a sound zero-dependency default (it powers BYOK key storage in larz.ai). For regulated or high-value secrets, a KMS or the cryptography package may still be preferable.