Course contentsShow
← Cloud and Infrastructure
Lesson 2282 of 2,98949. KMS and EncryptionFree lesson

Data Encryption Keys (DEK) and Key Encryption Keys (KEK)

Learn the envelope encryption pattern where DEKs encrypt data and KEKs encrypt DEKs for enhanced security.

Data Encryption Keys (DEK) and Key Encryption Keys (KEK)

What you'll learn: How envelope encryption uses two layers of keys—DEKs to encrypt data and KEKs to protect those DEKs—creating a powerful security pattern.

The Two-Layer Protection Model

Imagine you have a safe containing valuable documents (your data). Instead of using one master key that opens everything, envelope encryption uses two keys:

  1. Data Encryption Key (DEK): The key that actually encrypts your data
  2. Key Encryption Key (KEK): A master key that encrypts the DEK itself

This creates a "wrapped" or "enveloped" structure where your sensitive data is encrypted by a DEK, and that DEK is then encrypted by a KEK before storage.

Why Use This Pattern?

Performance: Symmetric encryption with DEKs is fast for large data volumes. You can generate unique DEKs per file or per object without overwhelming your KMS.

Security: The KEK stays in a hardware security module (HSM) or cloud KMS and never leaves. Even if encrypted data and encrypted DEKs are compromised, attackers can't decrypt without access to the KEK.

Key Rotation: You can rotate KEKs without re-encrypting all your data—just re-encrypt the DEKs. Similarly, rotating a DEK only requires re-encrypting one data object, not the entire key hierarchy.

The Envelope Encryption Flow

  1. Generate a random DEK (typically symmetric, like AES-256)
  2. Encrypt your data with the DEK
  3. Send the plaintext DEK to your KMS and request encryption using a KEK
  4. Store the encrypted DEK alongside your encrypted data
  5. Discard the plaintext DEK from memory

To decrypt: retrieve the encrypted DEK, ask KMS to decrypt it with the KEK, use the plaintext DEK to decrypt your data, then discard the plaintext DEK.

Key Takeaway: Envelope encryption separates data encryption (fast, local DEKs) from key protection (centralized, hardened KEKs), giving you both performance and security through layered key management.