Lion Cipher Lab

Encrypt data with AWS KMS envelope encryption

Why it matters

Almost every serious cloud system encrypts its data with a managed key service, and AWS KMS is the biggest. The pattern that makes it work at scale is envelope encryption: KMS only ever wraps a tiny 32-byte key, and your app uses that key to encrypt gigabytes locally. Get this wrong -- leave the plaintext data key in memory, skip the encryption context, or hand one identity both encrypt and decrypt -- and you have quietly undone the whole point of a key management service. Building it by hand once, against a free local emulator, is how you learn to read and fix a real KMS design.

What you'll learn

Steps in this lab

  1. What envelope encryption is, in one breath
  2. Run AWS locally for free with LocalStack
  3. Point boto3 at LocalStack with dummy credentials
  4. Create your customer-managed key (CMK) and an alias
  5. Envelope-encrypt a file with GenerateDataKey
  6. Decrypt it back by unwrapping the data key
  7. Prove the encryption context is a real lock
  8. Lock the key down: least-privilege key policy
  9. Turn on rotation -- and see why old data still decrypts
  10. The judgment: hand-rolled vs the AWS Encryption SDK

Open the full interactive lab →