Skip to main content

AWS Key Management Service (AWS KMS)

AWS KMS functionality is used to protect data in other AWS services and can be used in your applications too.

See AWS Key Management Service Developer Guide for general guidance using AWS KMS.

API Access

The IKMSClient interface and its implementation TKMSClient provides access to all AWS KMS operations.

The following example encrypts a string and then decrypts the ciphertext back to plaintext:

program EncryptIt;

{$APPTYPE CONSOLE}

uses
AWS.KMS,
System.Classes,
System.SysUtils;

var
KMS: IKMSClient;
EncryptRequest: IKMSEncryptRequest;
EncryptResponse: IKMSEncryptResponse;
DecryptRequest: IKMSDecryptRequest;
DecryptResponse: IKMSDecryptResponse;
DecryptedText: TStringStream;

begin
KMS := TKMSClient.Create;
try
// Encrypt some text using a key alias.
EncryptRequest := TKMSEncryptRequest.Create('alias/MyApp', 'My secret...');
EncryptResponse := KMS.Encrypt(EncryptRequest);

// Decrypt the ciphertext.
DecryptRequest := TKMSDecryptRequest.Create(EncryptResponse.CiphertextBlob);
DecryptResponse := KMS.Decrypt(DecryptRequest);

DecryptedText := TStringStream.Create;
try
DecryptedText.CopyFrom(DecryptResponse.Plaintext);
Writeln(Format('Decrypted: "%s"', [DecryptedText.DataString]));
finally
DecryptedText.Free;
end;
except
on E: EKMSException do
Writeln(E.ClassName, ': ', E.Message);
end;
end.

Keys can be created with CreateKey and given friendly names with CreateAlias.

Key Management Features

AWS KMS provides the following key management operations:

Cryptographic Operations

AWS KMS provides a simple interface to access cryptographic functionality:

Advanced Features of AWS KMS