// Glossary

Envelope Encryption

Last updated ·

Envelope encryption is the practice of encrypting data with a data encryption key (DEK) and then encrypting that DEK with a separate key encryption key (KEK). The wrapped DEK is stored next to the ciphertext, while the KEK stays in a key management service or another protected store and never travels with the data.

Why does envelope encryption matter?

AWS describes it in AWS KMS cryptography essentials as "the practice of encrypting plaintext data with a data key, and then encrypting the data key under another key." The structure has three practical effects:

  • A smaller blast radius. A copied database contains ciphertext and wrapped keys, which are useless without the KEK.
  • Cheaper re-keying. In AWS's words, "Instead of re-encrypting raw data multiple times with different keys, you can re-encrypt only the data keys that protect the raw data."
  • Separate keys per item or tenant. Google Cloud's envelope encryption guidance advises: "Do not use the same DEK to encrypt data from two different users."

How does EOXLABS apply it?

EOXLABS applies envelope encryption to secrets an application must store and later use, such as third-party OAuth refresh tokens. Each token is encrypted with AES-GCM under its own DEK. The DEK is wrapped with a KEK held outside the database, and the row stores the ciphertext, the wrapped DEK, the nonce and a key-version identifier. On Cloudflare Workers, both steps use the Web Crypto API, which supports AES-GCM for encryption and AES-KW for wrapKey() and unwrapKey():

const dek = await crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt']);
const iv = crypto.getRandomValues(new Uint8Array(12));
const ciphertext = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, dek, plaintext);
const wrappedDek = await crypto.subtle.wrapKey('raw', dek, kek, 'AES-KW');

An engineering note applies the idea to one specific case: envelope encryption for OAuth tokens. Envelope encryption complements a zero trust design: access control decides who may ask for a secret, and encryption limits the damage if that control fails.

What do teams get wrong about envelope encryption?

  • Rotating the KEK does not re-encrypt data. AWS's key rotation documentation is explicit: rotation "does not rotate the data keys that the KMS key generated or re-encrypt any data protected by the KMS key", and it "will not mitigate the effect of a compromised data key." A leaked DEK requires the affected data to be re-encrypted under a new one.
  • Disk encryption is not the same control. Storage-level encryption at rest protects lost disks. It does nothing about a valid database credential reading rows, which envelope encryption at the application layer does address.
  • Key wrapping is not a homemade construction. NIST SP 800-38F specifies approved key-wrap modes, AES Key Wrap (KW) and Key Wrap with Padding (KWP), that protect both the confidentiality and the integrity of keys.
  • Old key versions still matter. An immutable backup of an envelope-encrypted table can only be restored while the KEK versions that wrapped its DEKs still exist, so key retention must match backup retention.

Key management is part of EOXLABS's broader security and resilience work. Further terms are in the glossary.

→

Related

+

More glossary

Have a system that can’t go dark?

Start a project →