A developer needs to secure a configuration file containing sensitive application credentials that is in size. The developer wants to implement client-side encryption using a customer managed key in AWS Key Management Service (AWS KMS) before storing the file.
Which approach should the developer take to encrypt this file?
- Call the KMS GenerateDataKey API to retrieve a plaintext data key and an encrypted data key. Encrypt the configuration file locally using the plaintext data key, then delete the plaintext key from memory and store the encrypted configuration file with the encrypted data key.Answer
- BCall the KMS Encrypt API directly, passing the configuration file as the plaintext payload, and store the resulting ciphertext in the application storage.
- CCall the KMS GenerateDataKeyWithoutPlaintext API to receive an encrypted data key. Decrypt the data key using the KMS Decrypt API, encrypt the configuration file locally, and then discard the plaintext data key.
- DStore the configuration file as a secret in AWS Secrets Manager, and configure AWS Systems Manager Parameter Store to perform client-side envelope decryption of the secret values.
Answer
Call the KMS GenerateDataKey API to retrieve a plaintext data key and an encrypted data key. Encrypt the configuration file locally using the plaintext data key, then delete the plaintext key from memory and store the encrypted configuration file with the encrypted data key.
The configuration file is , which exceeds the limit for direct encryption using the AWS KMS `Encrypt` API. Therefore, client-side envelope encryption is required. Calling `GenerateDataKey` provides both the plaintext data key to perform the local encryption and the encrypted data key to be stored alongside the ciphertext for future decryption.
Step-by-Step Solution
Key Concept
AWS KMS Envelope Encryption Workflow