implementing-envelope-encryption-with-aws-kms

Implement envelope encryption using AWS KMS GenerateDataKey with AES-256-GCM local encryption.

954|172|Updated Mar 13, 2026
One-click install
npx skills add https://github.com/xalgord/xalgorix --skill implementing-envelope-encryption-with-aws-kms
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: implementing-envelope-encryption-with-aws-kms
Source: https://github.com/xalgord/xalgorix/tree/main/internal/tools/skills/data/cryptography/implementing-envelope-encryption-with-aws-kms
Command: npx skills add https://github.com/xalgord/xalgorix --skill implementing-envelope-encryption-with-aws-kms

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Encrypting large volumes of data directly with AWS KMS is limited to 4 KB per request and requires a network round-trip for every operation. This Skill guides the implementation of envelope encryption, where data is encrypted locally with a data encryption key (DEK) and only the DEK is protected by a KMS-managed master key.

Core Features & Use Cases

  • DEK Generation and Storage: Call the KMS GenerateDataKey API to obtain a plaintext and encrypted DEK, encrypt data locally with AES-256-GCM, and store only the encrypted DEK alongside the ciphertext.
  • Misconfiguration Detection: Identify overly broad KMS key policies, missing encryption contexts, plaintext DEK persistence, and missing CloudTrail logging or key rotation.
  • Key Lifecycle Management: Implement DEK caching to reduce KMS API calls, handle key rotation with re-encryption, and support multi-region encryption for disaster recovery.
  • Use Case: When building an application that stores sensitive records in AWS, use this Skill to encrypt each record locally with a unique DEK bound to an encryption context, so a compromised role cannot replay ciphertexts against other objects.

Quick Start

Implement envelope encryption for my application using AWS KMS GenerateDataKey and verify that decryption fails when the encryption context does not match.

Frequently Asked Questions about implementing-envelope-encryption-with-aws-kms

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement envelope encryption with AWS KMS?

Call the KMS GenerateDataKey API to receive a plaintext DEK and its encrypted ciphertext blob. Encrypt your data locally with the plaintext DEK using AES-256-GCM, store the encrypted DEK alongside the ciphertext, and wipe the plaintext DEK from memory.

What is the difference between direct KMS encryption and envelope encryption?

Direct KMS encryption is limited to 4 KB of data and requires a network round-trip per operation. Envelope encryption handles unlimited data sizes locally, reduces KMS API costs, and supports offline operation with cached DEKs.

Why does AWS KMS decryption fail with an encryption context mismatch?

KMS binds the encryption context as authenticated metadata during GenerateDataKey and Decrypt calls. If the context supplied at decryption does not exactly match the one used at encryption, KMS rejects the request, preventing ciphertext replay against other objects.

What are common AWS KMS key policy misconfigurations?

Granting kms:Decrypt on Resource: * or to broad principals lets any compromised role decrypt every DEK. Scope policies to specific key ARNs and principals, and prefer time-bound grants via CreateGrant with constraints over standing permissions.

Does AWS KMS support automatic key rotation for envelope encryption?

Customer-managed CMKs support automatic annual rotation in KMS. After rotation, existing encrypted DEKs should be re-wrapped with the new master key material, and CloudTrail should log all KMS calls for auditability.