Concepts¶
Envelope encryption¶
Every envelope is encrypted under its own fresh 256-bit data key. The data key is never stored in the clear. Instead, each recipient key wraps it, and the wrapped copies travel inside the envelope:
flowchart LR
P[plaintext] --> E[AES-256-GCM records]
D[fresh data key] --> E
D --> W1[wrapped by the primary key<br/>e.g. a KMS key]
D --> W2[wrapped by an escrow key<br/>e.g. an offline HPKE key]
C[encryption context] -. authenticated, never stored .-> E
E --> V[(envelope)]
W1 --> V
W2 --> V
Opening needs any one recipient key. Because only the small data key is wrapped, the key service sees one request per envelope, never the data, and moving an envelope to a new key rewrites only its recipient section, never the ciphertext.
The parts of the API¶
Term |
What it is |
|---|---|
|
The object you call: |
Provider |
A |
|
A key of one provider, named the way the provider names it, optionally with a version. |
Recipient key |
A key every envelope is sealed to: the |
Decryption key |
A key trusted for opening only, such as a retired primary key. |
|
What the data is and whom it belongs to. Authenticated, never stored. |
|
The limits and permissions every operation is checked against. Immutable, with a content-derived identifier. |
|
The sealed bytes. Not secret. |
Versions¶
A key service rotates a key by adding a new version. Envelopes always
record the exact, immutable version that wrapped them, so they open after any
number of rotations. A KeyRef without a version means “the current
version” when sealing; rewrap moves an envelope to the current version.
Versions also decide trust. A key named without a version trusts every version of that key, so a protector keeps opening envelopes after a rotation. A key pinned to a version trusts that version only, which suits a key that must not change under you, such as an audited escrow key.
Which keys may open an envelope¶
The envelope names the keys that wrapped its data key, but the reader decides
which of them it trusts. A Protector unwraps only with its recipient keys
and its decryption keys. A recipient that names any other key is never sent
to a key service.
This matters because a key service decrypts with any key the caller’s credentials allow. Without the rule, anyone who controls such a key (a key in another account that grants your role decrypt, or another tenant’s key) could seal arbitrary data that your service would accept as its own.
The encryption context¶
The context is a small mapping of text or bytes, such as
{"tenant": "acme", "table": "invoices", "row": "42"}. Sealing binds the
envelope to it through a commitment keyed from the data key; the context
itself is never stored. Opening with a different context fails.
Use it to bind data to where it belongs: the tenant, the purpose, the record it was written for. That stops a stolen or misrouted envelope from being opened in the wrong place. Do not put secrets in it: it is authenticated, not encrypted, and you need it again to open.
What is guaranteed¶
Confidentiality. Without a trusted recipient key, an envelope reveals nothing about its plaintext beyond its size.
Integrity. Any change, truncation, extension, or reordering of an envelope’s bytes is detected; streaming output becomes visible only after the last record verifies.
Key commitment. Every recipient recovers the same data key, so an envelope cannot decrypt to different plaintexts for different recipients.
Context binding. An envelope opens only with the context it was sealed with.
The threat model states each guarantee precisely, with the tests that check it.
What is not¶
Who sealed it. Anyone who can wrap to a recipient key can seal to it. With a public HPKE key, that is anyone who has the public key. When the origin matters, sign the data or the envelope as well.
Metadata. Key identifiers and versions, the number of recipients, the record size, and (for envelopes sealed in one call) the plaintext size are visible.
inspectshows exactly what is.A compromised host. Code running in your process can read what the SDK can read.
The format¶
The envelope format is specified byte by byte, with test vectors and a conformance suite that any implementation can run. A JavaScript implementation reads and writes the same envelopes.