One key per record, and the checks around it
Why envelopes
Sending every record to a key service to be encrypted is slow, costly and size-limited. So each record gets a fresh 256-bit data key that encrypts it locally, and only that 32-byte key goes to the key service to be wrapped. The wrapped key travels inside the envelope.
Rotating the master key then means rewrapping 32 bytes per record, not re-encrypting the data, and a second recipient (an escrow key, a second region) is one more wrap of the same small key.
What the checks catch
The binding. Each wrap is bound to the envelope’s header, so a wrapped key moved to another header won’t unwrap.
The commitments. AES-GCM alone doesn’t commit to its key: one ciphertext can be built to decrypt, differently, under two keys. A key commitment in the header rules that out. A keyed commitment to the tenant and purpose binds the record to one customer without storing either.
The records. Each one is authenticated with its position and a last-record flag, which is how the reader detects records that were reordered, cut off or appended.
What this lab leaves out
A real deployment uses a key service you don’t control from the browser (AWS KMS, Google Cloud KMS, Azure Key Vault, HashiCorp Vault) or public-key recipients, including post-quantum hybrid ones. Those live in the Python library. Streaming, range reads and rewrapping are Python-only too.
The lab shows that tampering is detected. It can’t show that a system is secure: that depends on who can call the key service, how keys are rotated and recovered, and what the application does with an error.
The same thing in Python
from cryptography_suite import EncryptionContext, Policy, Protector
from cryptography_suite.providers.hpke import HpkeRecipientProvider, generate_private_key
identity = generate_private_key() # in production: a key-service key
provider = HpkeRecipientProvider()
key = provider.add_identity("invoices", identity)
protector = Protector(provider=provider, policy=Policy(), primary_key=key)
context = EncryptionContext({"tenant": "acme"}, purpose="invoice-archive")
envelope = protector.seal(b"invoice 2026-0042: 1,200 EUR", context=context)
assert protector.open(envelope, context=context) == b"invoice 2026-0042: 1,200 EUR"From the project’s quick start. The format specification gives every byte you see above.
Sources and further reading
- Envelope format v4.0 (normative specification)cryptography-suite, 2026
- Threat model and security claimscryptography-suite, 2026
- Online Authenticated-Encryption and its Nonce-Reuse Misuse-Resistance (the STREAM construction)Hoang, Reyhanitabar, Rogaway and Vizár, CRYPTO 2015
- How to Abuse and Fix Authenticated Encryption Without Key CommitmentAlbertini, Duong, Gueron, Kölbl, Luykx and Schmieg, USENIX Security 2022
- RFC 5869: HMAC-based Extract-and-Expand Key Derivation Function (HKDF)IETF, 2010
- NIST SP 800-38D: Galois/Counter Mode (GCM) and GMACNIST, 2007