AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Container for the parameters to the Encrypt operation. Encrypts plaintext into ciphertext by using a customer master key. The Encrypt function has two primary use cases:

Unless you are moving encrypted data from one region to another, you don't use this function to encrypt a generated data key within a region. You retrieve data keys already encrypted by calling the GenerateDataKey or GenerateDataKeyWithoutPlaintext function. Data keys don't need to be encrypted again by calling Encrypt.

If you want to encrypt data locally in your application, you can use the GenerateDataKey function to return a plaintext data encryption key and a copy of the key encrypted under the customer master key (CMK) of your choosing.

Inheritance Hierarchy

System.Object
  Amazon.Runtime.AmazonWebServiceRequest
    Amazon.KeyManagementService.AmazonKeyManagementServiceRequest
      Amazon.KeyManagementService.Model.EncryptRequest

Namespace: Amazon.KeyManagementService.Model
Assembly: AWSSDK.KeyManagementService.dll
Version: 3.x.y.z

Syntax

C#
public class EncryptRequest : AmazonKeyManagementServiceRequest
         IAmazonWebServiceRequest

The EncryptRequest type exposes the following members

Constructors

NameDescription
Public Method EncryptRequest()

Properties

NameTypeDescription
Public Property EncryptionContext System.Collections.Generic.Dictionary<System.String, System.String>

Gets and sets the property EncryptionContext.

Name-value pair that specifies the encryption context to be used for authenticated encryption. If used here, the same value must be supplied to the Decrypt API or decryption will fail. For more information, see Encryption Context.

Public Property GrantTokens System.Collections.Generic.List<System.String>

Gets and sets the property GrantTokens.

A list of grant tokens.

For more information, see Grant Tokens in the AWS Key Management Service Developer Guide.

Public Property KeyId System.String

Gets and sets the property KeyId.

A unique identifier for the customer master key. This value can be a globally unique identifier, a fully specified ARN to either an alias or a key, or an alias name prefixed by "alias/".

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Alias ARN Example - arn:aws:kms:us-east-1:123456789012:alias/MyAliasName

  • Globally Unique Key ID Example - 12345678-1234-1234-1234-123456789012

  • Alias Name Example - alias/MyAliasName

Public Property Plaintext System.IO.MemoryStream

Gets and sets the property Plaintext.

Data to be encrypted.

Examples

The following example encrypts data with the specified customer master key (CMK).

To encrypt data


var response = client.Encrypt(new EncryptRequest 
{
    KeyId = "1234abcd-12ab-34cd-56ef-1234567890ab", // The identifier of the CMK to use for encryption. You can use the key ID or Amazon Resource Name (ARN) of the CMK, or the name or ARN of an alias that refers to the CMK.
    Plaintext = new MemoryStream() // The data to encrypt.
});

MemoryStream ciphertextBlob = response.CiphertextBlob; // The encrypted data (ciphertext).
string keyId = response.KeyId; // The ARN of the CMK that was used to encrypt the data.

            

Version Information

.NET Standard:
Supported in: 1.3

.NET Framework:
Supported in: 4.5, 4.0, 3.5

Portable Class Library:
Supported in: Windows Store Apps
Supported in: Windows Phone 8.1
Supported in: Xamarin Android
Supported in: Xamarin iOS (Unified)
Supported in: Xamarin.Forms