Envelope Encryption and Data Keys
See how KMS protects a data key that encrypts your real data.
Envelope Encryption and Data Keys is a free AWS Security Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Large Data Problem
KMS can encrypt only small payloads (about 4 KB) directly. Real data, files, volumes, and databases, is far larger.
Envelope encryption solves this: you encrypt your big data with a data key, then encrypt that data key with a KMS key. This is how AWS encrypts everything at scale.
What a Data Key Is
A data key is a normal encryption key (like AES-256) generated by KMS for encrypting your actual data.
- Unlike KMS keys, the data key's plaintext leaves KMS briefly so you can use it.
- KMS also returns an encrypted copy of the data key.
GenerateDataKey
You call GenerateDataKey, naming a KMS key. KMS returns:
- A plaintext data key to encrypt your data immediately.
- An encrypted data key (wrapped by the KMS key) to store alongside the ciphertext.
You then discard the plaintext data key from memory.
aws kms generate-data-key \
--key-id alias/my-app-key \
--key-spec AES_256The Envelope Pattern
The flow is:
- Encrypt data with the plaintext data key.
- Store the encrypted data key next to the ciphertext.
- Throw away the plaintext data key.
The data key is "in an envelope" sealed by the KMS key, hence the name.
Decrypting with the Envelope
To decrypt, you reverse the process:
- Send the encrypted data key to KMS Decrypt.
- KMS returns the plaintext data key.
- Use it to decrypt your data, then discard it.
Only KMS can unwrap the data key, so access to the KMS key controls everything.
Why Envelope Encryption Helps
Envelope encryption gives the best of both worlds:
- Fast local encryption of large data with the data key.
- Strong central control because the data key is useless without the KMS key.
You also reduce KMS calls, since one data key can protect lots of data.
Caching Data Keys
For high-volume workloads, the AWS Encryption SDK can cache data keys to reuse them across many encryptions.
This cuts KMS request costs and latency, with configurable limits so a cached key is not reused too long or too widely, balancing performance against security.
How Services Use It Internally
When you enable encryption on S3, EBS, or RDS, AWS performs envelope encryption for you.
The service requests a data key from your KMS key, encrypts the data, and stores the wrapped data key. You simply pick the KMS key; the envelope mechanics are automatic.
The AWS Encryption SDK
The AWS Encryption SDK is a client-side library that implements envelope encryption correctly in your own apps.
It handles data key generation, encryption context, and storing the wrapped key with the ciphertext, so you do not implement the error-prone crypto plumbing yourself.
GenerateDataKeyWithoutPlaintext
A variant, GenerateDataKeyWithoutPlaintext, returns only the encrypted data key.
It is used when you want to generate and store a data key now but decrypt it only later, at the moment of use. This keeps the plaintext key out of memory until it is actually needed, reducing exposure for keys provisioned ahead of time.
Why It Matters for the Exam
Envelope encryption explains why KMS scales and how a single KMS key protects terabytes of data.
Expect questions on the GenerateDataKey flow, what leaves KMS (the data key, briefly), and why controlling the KMS key controls all derived data.
Quick Check
Test the envelope flow.
Recap
You learned envelope encryption.
- GenerateDataKey returns a plaintext and an encrypted data key.
- Encrypt data locally with the plaintext key, store the wrapped key, discard the plaintext.
- Only the KMS key can unwrap the data key, giving central control over all data.
Frequently asked questions
Is the “Envelope Encryption and Data Keys” lesson free?
Yes — the full text of “Envelope Encryption and Data Keys” is free to read here on the web, and the AWS Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Security Academy course, upgrade to CoddyKit PRO.
What will I learn in “Envelope Encryption and Data Keys”?
See how KMS protects a data key that encrypts your real data. You practise AWS Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Security Academy?
No prior experience is required. AWS Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Envelope Encryption and Data Keys” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Security Academy lesson?
Yes. Every AWS Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- What KMS Keys Are and Do
- Symmetric, Asymmetric, and Multi-Region Keys
- Key Policies, Grants, and Conditions
- Envelope Encryption and Data Keys