Skill 2.2.4
Use encryption keys to encrypt and decrypt data.
Key Concepts
Encrypt and Decrypt work on up to 4 KB of data, which suits secrets such as passwords or API keys. For larger data you use envelope encryption: GenerateDataKey returns a plaintext data key and an encrypted copy; you encrypt the data locally, discard the plaintext key and store the encrypted key with the data. To decrypt, call Decrypt on the data key, then decrypt the data locally.
An encryption context, a set of non-secret key-value pairs, can be passed to these calls. The same context must be supplied to decrypt, which binds the ciphertext to its purpose and shows up in CloudTrail logs. The AWS Encryption SDK implements envelope encryption and data key caching for you.
Cross-account use of a customer managed KMS key needs two permissions: the key policy in the owning account must allow the other account (or a role in it), and an IAM policy in the other account must allow its principals to use the key, for example kms:Decrypt. AWS managed keys cannot be shared across accounts, so data that must be shared needs a customer managed key.
Typical cases include reading SSE-KMS encrypted S3 objects from another account, sharing encrypted EBS or RDS snapshots, and subscribing to encrypted SNS topics or SQS queues. Grants can give another account's principal temporary, specific use of a key.
For customer managed symmetric keys you can enable automatic rotation, with a rotation period between 90 and 2,560 days (365 by default), and also trigger on-demand rotation. AWS managed keys rotate automatically every year and cannot be changed. The key ID and ARN stay the same and KMS keeps old key material, so existing data still decrypts without re-encryption.
Automatic rotation is not available for asymmetric keys, HMAC keys or keys with imported material. A symmetric key with imported material can be rotated on demand after new key material is imported into it. Asymmetric and HMAC keys are rotated manually by creating a new key and pointing an alias at it, so applications that use the alias pick up the new key.