amazon-s3-encryption-client-dotnet

Amazon S3 Encryption Client for .NET

Overview

These are the API docs for the Amazon S3 Encryption client for .NET. There exist two (2) clients in this product:

The AmazonS3EncryptionClientV2 has an identical API to the AmazonS3EncryptionClientV4 that is in the AWS SDK for .NET. The main difference is that AmazonS3EncryptionClientV2 can only decrypt message with content encryption AesGcmWithCommitment, while AmazonS3EncryptionClientV4 can encrypt or decrypt message with content encryption AesGcmWithCommitment. It is recommended to use AesGcmWithCommitment instead of AesGcm without key commitment because key commitment prevents attackers from crafting ciphertexts that decrypt to different plaintexts under different keys, protecting against key substitution attacks when on instruction file mode.

How to use the AmazonS3EncryptionClientV4 client

The AmazonS3EncryptionClientV4 supports the following encryption methods for encrypting DEKs (Data encryption keys):

Object content is encrypted using committing AES-GCM (default) with generated DEKs which are stored in the S3 object metadata or in a separate instruction file (as configured).

Data Key Encryption

AWS KMS + Context

To use “AWS KMS + Context”, you must supply an EncryptionMaterialsV4 instance with the following information:

var encryptionContext = new Dictionary<string, string>();
var encryptionMaterial =
    new EncryptionMaterialsV4("1234abcd-12ab-34cd-56ef-1234567890ab", KmsType.KmsContext, encryptionContext);
var configuration = new AmazonS3CryptoConfigurationV4(SecurityProfile.V4, CommitmentPolicy.RequireEncryptRequireDecrypt, ContentEncryptionAlgorithm.AesGcmWithCommitment);
var encryptionClient = new AmazonS3EncryptionClientV4(configuration, encryptionMaterial);

RSA-OAEP-SHA1

To use “RSA-OAEP-SHA1”, you must supply an EncryptionMaterialsV4 instance with the following information:

var asymmetricAlgorithm = RSA.Create();
var encryptionMaterial = new EncryptionMaterialsV4(asymmetricAlgorithm, AsymmetricAlgorithmType.RsaOaepSha1);
var configuration = new AmazonS3CryptoConfigurationV4(SecurityProfile.V4, CommitmentPolicy.RequireEncryptRequireDecrypt, ContentEncryptionAlgorithm.AesGcmWithCommitment);
var encryptionClient = new AmazonS3EncryptionClientV4(configuration, encryptionMaterial);

AES-GCM

To use “AES-GCM”, you must supply an EncryptionMaterialsV4 instance with the following information:

var symmetricAlgorithm = Aes.Create();
var encryptionMaterial = new EncryptionMaterialsV4(symmetricAlgorithm, SymmetricAlgorithmType.AesGcm);
var configuration = new AmazonS3CryptoConfigurationV4(SecurityProfile.V4, CommitmentPolicy.RequireEncryptRequireDecrypt, ContentEncryptionAlgorithm.AesGcmWithCommitment);
var encryptionClient = new AmazonS3EncryptionClientV4(configuration, encryptionMaterial);

CommitmentPolicy and ContentEncryptionAlgorithm

Starting with Amazon S3 Encryption Client for .NET V4, you can encrypt objects with AES-GCM with key commitment (default for V4), which protects your data against key substitution attacks. To help you migrate from AES-GCM to AES-GCM with key commitment, this version includes three commitment policies.

For more information, see S3 Encryption Client Migration (V2 to V4).

Storage Mode

You can specify a storage mode for the encrypted data key and associated metadata needed for decryption of an object:

This can be set on the AmazonS3CryptoConfigurationV4 instance:

var configuration = new AmazonS3CryptoConfigurationV4(SecurityProfile.V4)
{
    StorageMode.InstructionFile
}

Security Profile

A security profile setting needs to be passed to the constructor of the AmazonS3CryptoConfigurationV4 instance, either:

Unless you are migrating existing applications from legacy content encryption message format (message encrypted with AmazonS3EncryptionClient which uses AES CBC), use V4. If you need legacy mode:

var configuration = new AmazonS3CryptoConfigurationV4(SecurityProfile.V4AndLegacy);

Multipart Uploads

The AmazonS3EncryptionClientV4 extends the base AmazonS3Client. You can use multipart upload using the same APIs: https://docs.aws.amazon.com/AmazonS3/latest/dev/LLuploadFileDotNet.html

Transfer Utility Integration

The AmazonS3EncryptionClientV4 extends the base AmazonS3Client. You can use the TransferUtility just as you would using the base AmazonS3Client: https://docs.aws.amazon.com/AmazonS3/latest/dev/HLuploadFileDotNet.html