KMS
AWS Key Management Service for creating and controlling cryptographic keys used for encryption, decryption, and digital signatures.
Configuration
| Property | Value |
|---|---|
| Protocol | AwsJson1_1 |
| Signing Name | kms |
| Target Prefix | TrentService |
| Persistence | No |
Quick Start
Create a key, encrypt data, then decrypt it:
# Create a symmetric encryption key
KEY_ID=$(curl -s http://localhost:4566 \
-H "Content-Type: application/x-amz-json-1.1" \
-H "X-Amz-Target: TrentService.CreateKey" \
-H "Authorization: AWS4-HMAC-SHA256 Credential=test/20260421/us-east-1/kms/aws4_request, SignedHeaders=host, Signature=fake" \
-d '{"KeySpec":"SYMMETRIC_DEFAULT","KeyUsage":"ENCRYPT_DECRYPT","Description":"My app key"}' \
| jq -r '.KeyMetadata.KeyId')
echo "Key ID: $KEY_ID"
# Create an alias
curl -s http://localhost:4566 \
-H "Content-Type: application/x-amz-json-1.1" \
-H "X-Amz-Target: TrentService.CreateAlias" \
-H "Authorization: AWS4-HMAC-SHA256 Credential=test/20260421/us-east-1/kms/aws4_request, SignedHeaders=host, Signature=fake" \
-d "{\"AliasName\":\"alias/my-app-key\",\"TargetKeyId\":\"$KEY_ID\"}"
# Encrypt data (Plaintext must be base64-encoded)
CIPHERTEXT=$(curl -s http://localhost:4566 \
-H "Content-Type: application/x-amz-json-1.1" \
-H "X-Amz-Target: TrentService.Encrypt" \
-H "Authorization: AWS4-HMAC-SHA256 Credential=test/20260421/us-east-1/kms/aws4_request, SignedHeaders=host, Signature=fake" \
-d "{\"KeyId\":\"alias/my-app-key\",\"Plaintext\":\"SGVsbG8gV29ybGQ=\"}" \
| jq -r '.CiphertextBlob')
# Decrypt data (KeyId not needed — it's embedded in the ciphertext)
curl -s http://localhost:4566 \
-H "Content-Type: application/x-amz-json-1.1" \
-H "X-Amz-Target: TrentService.Decrypt" \
-H "Authorization: AWS4-HMAC-SHA256 Credential=test/20260421/us-east-1/kms/aws4_request, SignedHeaders=host, Signature=fake" \
-d "{\"CiphertextBlob\":\"$CIPHERTEXT\"}"Operations
Key Lifecycle
CreateKey— create a new KMS key- Input:
KeySpec(SYMMETRIC_DEFAULT,RSA_2048,RSA_3072,RSA_4096,ECC_NIST_P256,ECC_NIST_P384,HMAC_256),KeyUsage(ENCRYPT_DECRYPT,SIGN_VERIFY,GENERATE_VERIFY_MAC),Description,Tags - Returns:
KeyMetadatawithKeyId(UUID),Arn,KeyState: "Enabled",KeySpec,KeyUsage,CreationDate
- Input:
DescribeKey— get metadata for a key or alias- Input:
KeyId(key ID, key ARN, or alias name likealias/my-key) - Returns:
KeyMetadata(same as CreateKey response)
- Input:
ListKeys— list all keys in the account/region- Input: optional
Limit,Marker - Returns: paginated
Keyslist withKeyIdandKeyArn
- Input: optional
EnableKey— re-enable a disabled key- Input:
KeyId
- Input:
DisableKey— disable a key (prevents encrypt/decrypt use)- Input:
KeyId
- Input:
ScheduleKeyDeletion— schedule a key for deletion- Input:
KeyId,PendingWindowInDays(7–30 days) - Returns:
KeyId,DeletionDate - Sets key state to
PendingDeletion
- Input:
Aliases
CreateAlias— create a friendly alias for a key- Input:
AliasName(must start withalias/, cannot start withalias/aws/),TargetKeyId
- Input:
DeleteAlias— delete an alias (does not delete the key)- Input:
AliasName
- Input:
ListAliases— list aliases, optionally filtered by key ID- Input: optional
KeyId,Limit,Marker - Returns: paginated
Aliaseslist withAliasName,AliasArn,TargetKeyId
- Input: optional
UpdateAlias— point an existing alias to a different key (useful for key rotation)- Input:
AliasName,TargetKeyId
- Input:
UpdateKeyDescription— update the description of a KMS key- Input:
KeyId,Description
- Input:
Key Rotation
GetKeyRotationStatus— check whether automatic key rotation is enabled for a key- Input:
KeyId - Returns:
KeyRotationEnabled(boolean)
- Input:
EnableKeyRotation— enable automatic annual key rotation for a symmetric key- Input:
KeyId
- Input:
DisableKeyRotation— disable automatic key rotation for a key- Input:
KeyId
- Input:
Grants
CreateGrant— create a grant that allows a grantee to use a key- Input:
KeyId,GranteePrincipal,Operations(list of allowed operations) - Returns:
GrantId,GrantToken
- Input:
ListGrants— list grants on a key- Input:
KeyId, optionalLimit,Marker - Returns: paginated
Grantslist
- Input:
ListRetirableGrants— list grants where the given principal is the retiring principal- Input:
RetiringPrincipal, optionalLimit,Marker - Returns: paginated
Grantslist
- Input:
RetireGrant— retire a grant using the grant token or grant ID- Input:
GrantTokenor (KeyId+GrantId)
- Input:
RevokeGrant— revoke a grant immediately- Input:
KeyId,GrantId
- Input:
Key Policies
GetKeyPolicy— get the key policy document for a KMS key- Input:
KeyId,PolicyName(must be"default") - Returns:
Policy(JSON string)
- Input:
PutKeyPolicy— set the key policy for a KMS key- Input:
KeyId,PolicyName(must be"default"),Policy(JSON string)
- Input:
ListKeyPolicies— list policy names for a key (always returns["default"])- Input:
KeyId, optionalLimit,Marker - Returns:
PolicyNames
- Input:
Cryptographic Operations
Encrypt— encrypt plaintext using a KMS key- Input:
KeyId,Plaintext(base64-encoded bytes, max 4096 bytes) - Returns:
CiphertextBlob(base64-encoded, includes key ID for decryption),KeyId,EncryptionAlgorithm
- Input:
Decrypt— decrypt ciphertext (key is resolved from ciphertext blob)- Input:
CiphertextBlob(base64-encoded), optionalKeyId,EncryptionAlgorithm - Returns:
Plaintext(base64-encoded),KeyId,EncryptionAlgorithm
- Input:
GenerateDataKey— generate a data key for envelope encryption- Input:
KeyId,KeySpec(AES_128orAES_256) - Returns:
CiphertextBlob(encrypted data key),Plaintext(raw data key — use for encryption, then discard),KeyId
- Input:
GenerateDataKeyWithoutPlaintext— generate a data key, return only the encrypted form- Input:
KeyId,KeySpec - Returns:
CiphertextBlobonly (no plaintext — for deferred decryption scenarios)
- Input:
ReEncrypt— decrypt ciphertext and re-encrypt under a different key- Input:
CiphertextBlob,DestinationKeyId, optionalSourceKeyId - Returns: new
CiphertextBlobencrypted underDestinationKeyId
- Input:
GenerateRandom— generate cryptographically random bytes- Input:
NumberOfBytes(1–1024) - Returns:
Plaintext(base64-encoded random bytes)
- Input:
Curl Examples
# 1. Generate a data key for envelope encryption
curl -s http://localhost:4566 \
-H "Content-Type: application/x-amz-json-1.1" \
-H "X-Amz-Target: TrentService.GenerateDataKey" \
-H "Authorization: AWS4-HMAC-SHA256 Credential=test/20260421/us-east-1/kms/aws4_request, SignedHeaders=host, Signature=fake" \
-d '{"KeyId":"alias/my-app-key","KeySpec":"AES_256"}'
# 2. List all aliases
curl -s http://localhost:4566 \
-H "Content-Type: application/x-amz-json-1.1" \
-H "X-Amz-Target: TrentService.ListAliases" \
-H "Authorization: AWS4-HMAC-SHA256 Credential=test/20260421/us-east-1/kms/aws4_request, SignedHeaders=host, Signature=fake" \
-d '{}'
# 3. Re-encrypt data under a new key
curl -s http://localhost:4566 \
-H "Content-Type: application/x-amz-json-1.1" \
-H "X-Amz-Target: TrentService.ReEncrypt" \
-H "Authorization: AWS4-HMAC-SHA256 Credential=test/20260421/us-east-1/kms/aws4_request, SignedHeaders=host, Signature=fake" \
-d '{"CiphertextBlob":"<base64-ciphertext>","DestinationKeyId":"<new-key-id>"}'SDK Example
import {
KMSClient,
CreateKeyCommand,
CreateAliasCommand,
EncryptCommand,
DecryptCommand,
GenerateDataKeyCommand,
} from '@aws-sdk/client-kms';
const kms = new KMSClient({
region: 'us-east-1',
endpoint: 'http://localhost:4566',
credentials: { accessKeyId: 'test', secretAccessKey: 'test' },
});
// Create symmetric key
const { KeyMetadata } = await kms.send(new CreateKeyCommand({
KeySpec: 'SYMMETRIC_DEFAULT',
KeyUsage: 'ENCRYPT_DECRYPT',
Description: 'My application encryption key',
}));
const keyId = KeyMetadata!.KeyId!;
// Create alias
await kms.send(new CreateAliasCommand({
AliasName: 'alias/my-app-key',
TargetKeyId: keyId,
}));
// Encrypt data
const plaintext = Buffer.from('Hello, World!');
const { CiphertextBlob } = await kms.send(new EncryptCommand({
KeyId: 'alias/my-app-key',
Plaintext: plaintext,
}));
console.log('Ciphertext length:', CiphertextBlob!.length);
// Decrypt (no KeyId needed — it's in the ciphertext)
const { Plaintext } = await kms.send(new DecryptCommand({
CiphertextBlob,
}));
console.log('Decrypted:', Buffer.from(Plaintext!).toString()); // Hello, World!
// Envelope encryption: generate a data key
const { Plaintext: dataKey, CiphertextBlob: encryptedDataKey } = await kms.send(
new GenerateDataKeyCommand({
KeyId: keyId,
KeySpec: 'AES_256',
})
);
// Use dataKey to encrypt your data locally, then discard dataKey
// Store encryptedDataKey alongside your encrypted data
console.log('Data key length:', dataKey!.length); // 32 bytes for AES_256Behavior Notes
- KMS uses AES-GCM symmetric encryption internally, so
Encrypt/Decryptroundtrips work correctly. - The ciphertext blob embeds the key ID so
Decryptcan resolve the key without aKeyIdparameter. - Keys are created in
Enabledstate immediately — no provisioning delay. ScheduleKeyDeletionsets state toPendingDeletionbut does not actually delete the key after the window in AWSim.GenerateDataKeyreturns both a plaintext key (for immediate use) and an encrypted copy (to store) — this enables envelope encryption without exposing the master key.GenerateRandomreturns cryptographically random bytes and does not require a key ID.- Key rotation (
EnableKeyRotation,DisableKeyRotation) state is stored per key but no actual rotation occurs in AWSim. - Grants (
CreateGrant,ListGrants, etc.) are stored and returned correctly but are not enforced for cryptographic operations. - Key policies (
GetKeyPolicy,PutKeyPolicy) are stored and returned but are not enforced. - Key material is in-memory only and lost on restart (no persistence).