Encryption Context for Access Control
You'll learn how to use additional authenticated data (AAD) in encryption operations to bind ciphertext to specific contexts, preventing misuse even if keys are compromised.
What Is Encryption Context?
Encryption context is a set of key-value pairs you provide during encryption that becomes cryptographically bound to the resulting ciphertext. Think of it like addressing an envelope: the letter inside (data) gets sealed, but the "To:" address is visible and verified. If someone tries to decrypt the ciphertext with a different context than what was used during encryption, the operation fails—even with the correct key.
This is implemented as Additional Authenticated Data (AAD) in authenticated encryption schemes. The context isn't encrypted itself, but it's included in the authentication tag calculation.
Why This Matters for Access Control
Imagine a KMS key that multiple services share. Without encryption context, any service with key permissions could decrypt data encrypted by another service. By requiring context like {"service": "billing", "department": "finance"}, you enforce that only callers providing matching context can decrypt.
You can write key policies that permit decryption only when specific context values are present. For example, permit kms:Decrypt only if "department": "finance" exists in the context. This creates fine-grained access control beyond simple IAM permissions.
Practical Pattern
During encryption, specify context that represents the data's ownership or purpose. During decryption, provide the same context. Store the context (unencrypted) alongside the ciphertext—you'll need it later, and it's safe since it's authenticated but not secret.
Key Takeaway:
Encryption context binds ciphertext to specific usage scenarios through authenticated metadata, enabling context-aware access control that prevents authorized users from decrypting data outside their intended scope.