Multi-keyrings - AWS Database Encryption SDK

Multi-keyrings

Our client-side encryption library was renamed to the AWS Database Encryption SDK. This developer guide still provides information on the DynamoDB Encryption Client.

You can combine keyrings into a multi-keyring. A multi-keyring is a keyring that consists of one or more individual keyrings of the same or a different type. The effect is like using several keyrings in a series. When you use a multi-keyring to encrypt data, any of the wrapping keys in any of its keyrings can decrypt that data.

When you create a multi-keyring to encrypt data, you designate one of the keyrings as the generator keyring. All other keyrings are known as child keyrings. The generator keyring generates and encrypts the plaintext data key. Then, all of the wrapping keys in all of the child keyrings encrypt the same plaintext data key. The multi-keyring returns the plaintext key and one encrypted data key for each wrapping key in the multi-keyring. If the generator keyring is a KMS keyring, the generator key in the AWS KMS keyring generates and encrypts the plaintext key. Then, all additional AWS KMS keys in the AWS KMS keyring, and all wrapping keys in all child keyrings in the multi-keyring, encrypt the same plaintext key.

When decrypting, the AWS Database Encryption SDK uses the keyrings to try to decrypt one of the encrypted data keys. The keyrings are called in the order that they are specified in the multi-keyring. Processing stops as soon as any key in any keyring can decrypt an encrypted data key.

To create a multi-keyring, first instantiate the child keyrings. In this example, we use an AWS KMS keyring and a Raw AES keyring, but you can combine any supported keyrings in a multi-keyring.

Java
// 1. Create the raw AES keyring. final MaterialProviders matProv = MaterialProviders.builder() .MaterialProvidersConfig(MaterialProvidersConfig.builder().build()) .build(); final CreateRawAesKeyringInput createRawAesKeyringInput = CreateRawAesKeyringInput.builder() .keyName("AES_256_012") .keyNamespace("HSM_01") .wrappingKey(AESWrappingKey) .wrappingAlg(AesWrappingAlg.ALG_AES256_GCM_IV12_TAG16) .build(); IKeyring rawAesKeyring = matProv.CreateRawAesKeyring(createRawAesKeyringInput); // 2. Create the AWS KMS keyring. final CreateAwsKmsMrkMultiKeyringInput createAwsKmsMrkMultiKeyringInput = CreateAwsKmsMrkMultiKeyringInput.builder() .generator(kmsKeyArn) .build(); IKeyring awsKmsMrkMultiKeyring = matProv.CreateAwsKmsMrkMultiKeyring(createAwsKmsMrkMultiKeyringInput);
C# / .NET
// 1. Create the raw AES keyring. var keyNamespace = "HSM_01"; var keyName = "AES_256_012"; var matProv = new MaterialProviders(new MaterialProvidersConfig()); var createRawAesKeyringInput = new CreateRawAesKeyringInput { KeyName = "keyName", KeyNamespace = "myNamespaces", WrappingKey = AESWrappingKey, WrappingAlg = AesWrappingAlg.ALG_AES256_GCM_IV12_TAG16 }; var rawAesKeyring = matProv.CreateRawAesKeyring(createRawAesKeyringInput); // 2. Create the AWS KMS keyring. // We create a MRK multi keyring, as this interface also supports // single-region KMS keys, // and creates the KMS client for us automatically. var createAwsKmsMrkMultiKeyringInput = new CreateAwsKmsMrkMultiKeyringInput { Generator = keyArn }; var awsKmsMrkMultiKeyring = matProv.CreateAwsKmsMrkMultiKeyring(createAwsKmsMrkMultiKeyringInput);

Next, create the multi-keyring and specify its generator keyring, if any. In this example, we create a multi-keyring in which the AWS KMS keyring is the generator keyring and the AES keyring is the child keyring.

Java

The Java CreateMultiKeyringInput constructor lets you define a generator keyring and child keyrings. The resulting createMultiKeyringInput object is immutable.

final CreateMultiKeyringInput createMultiKeyringInput = CreateMultiKeyringInput.builder() .generator(awsKmsMrkMultiKeyring) .childKeyrings(Collections.singletonList(rawAesKeyring)) .build(); IKeyring multiKeyring = matProv.CreateMultiKeyring(createMultiKeyringInput);
C# / .NET

The .NET CreateMultiKeyringInput constructor lets you define a generator keyring and child keyrings. The resulting CreateMultiKeyringInput object is immutable.

var createMultiKeyringInput = new CreateMultiKeyringInput { Generator = awsKmsMrkMultiKeyring, ChildKeyrings = new List<IKeyring> { rawAesKeyring } }; var multiKeyring = matProv.CreateMultiKeyring(createMultiKeyringInput);

Now, you can use the multi-keyring to encrypt and decrypt data.