Course contentsShow
← Security
Lesson 308 of 3,0527. Randomness and Key ManagementFree lesson

Key Storage Encryption and Protection

Techniques for encrypting keys at rest using key-encrypting keys (KEKs), master keys, and key wrapping algorithms.

Key Storage Encryption and Protection

What You'll Learn

You'll learn how cryptographic keys themselves are encrypted when stored, using special key-encrypting keys and wrapping techniques to protect them at rest.


The Problem: Keys Need Protection Too

We've learned how to generate strong cryptographic keys using CSPRNGs, HSMs, and TPMs. But once generated, where do these keys live? Storing raw keys on disk or in memory is dangerous—if an attacker gains file system access, they can steal everything.

The solution: encrypt the keys themselves before storing them.


Key-Encrypting Keys (KEKs)

A Key-Encrypting Key (KEK) is a special key whose only job is to encrypt other keys. Think of it as a master lock:

  • Data Encryption Keys (DEKs) encrypt your actual data
  • KEKs encrypt the DEKs before they're stored
  • KEKs are often stored in hardware (HSM/TPM) or derived from passwords

This creates a hierarchy: to access data, an attacker must first decrypt the DEK using the KEK.


Master Keys and Key Hierarchies

Master keys sit at the top of a key hierarchy. They encrypt KEKs, which encrypt DEKs. This layering means:

  • Only the master key needs extreme protection (hardware storage)
  • DEKs can be rotated without re-encrypting all data
  • Access control happens at the KEK/master key level

Key Wrapping Algorithms

Key wrapping is a specialized encryption mode designed specifically for encrypting keys. Unlike general-purpose encryption, key wrapping:

  • Adds integrity protection (detects tampering)
  • Uses algorithms like AES-KW (Key Wrap) defined in RFC 3394
  • Ensures wrapped keys cannot be modified undetected

It's like putting a key in a tamper-evident security envelope rather than a regular one.


Key Takeaway: Keys at rest are protected by encrypting them with Key-Encrypting Keys (KEKs) using key wrapping algorithms, creating hierarchies where only the master key requires maximum-security storage like HSMs or TPMs.