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.

Encrypts data on the server side with a new customer master key (CMK) without exposing the plaintext of the data on the client side. The data is first decrypted and then reencrypted. You can also use this operation to change the encryption context of a ciphertext.

You can reencrypt data using CMKs in different AWS accounts.

Unlike other operations, ReEncrypt is authorized twice, once as ReEncryptFrom on the source CMK and once as ReEncryptTo on the destination CMK. We recommend that you include the "kms:ReEncrypt*" permission in your key policies to permit reencryption from or to the CMK. This permission is automatically included in the key policy when you create a CMK through the console, but you must include it manually when you create a CMK programmatically or when you set a key policy with the PutKeyPolicy operation.


For .NET Core and PCL this operation is only available in asynchronous form. Please refer to ReEncryptAsync.

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


public abstract ReEncryptResponse ReEncrypt(
         ReEncryptRequest request
Type: Amazon.KeyManagementService.Model.ReEncryptRequest

Container for the necessary parameters to execute the ReEncrypt service method.

Return Value
The response from the ReEncrypt service method, as returned by KeyManagementService.


DependencyTimeoutException The system timed out while trying to fulfill the request. The request can be retried.
DisabledException The request was rejected because the specified CMK is not enabled.
InvalidCiphertextException The request was rejected because the specified ciphertext, or additional authenticated data incorporated into the ciphertext, such as the encryption context, is corrupted, missing, or otherwise invalid.
InvalidGrantTokenException The request was rejected because the specified grant token is not valid.
InvalidKeyUsageException The request was rejected because the specified KeySpec value is not valid.
KeyUnavailableException The request was rejected because the specified CMK was not available. The request can be retried.
KMSInternalException The request was rejected because an internal exception occurred. The request can be retried.
KMSInvalidStateException The request was rejected because the state of the specified resource is not valid for this request. For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key in the AWS Key Management Service Developer Guide.
NotFoundException The request was rejected because the specified entity or resource could not be found.


The following example reencrypts data with the specified CMK.

To reencrypt data

var response = client.ReEncrypt(new ReEncryptRequest 
    CiphertextBlob = new MemoryStream(), // The data to reencrypt.
    DestinationKeyId = "0987dcba-09fe-87dc-65ba-ab0987654321" // The identifier of the CMK to use to reencrypt the data. 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.

MemoryStream ciphertextBlob = response.CiphertextBlob; // The reencrypted data.
string keyId = response.KeyId; // The ARN of the CMK that was used to reencrypt the data.
string sourceKeyId = response.SourceKeyId; // The ARN of the CMK that was used to originally encrypt the data.


Version Information

.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

See Also