Re-encrypts ciphertext. When you call this operation, KMS first decrypts the specified ciphertext and then uses a different CMK to encrypt the obtained plaintext data or data key and return ciphertext.

You can call this operation in the following scenarios:

  • After the CMK that was used to encrypt your data is rotated, you can call this operation to use the latest CMK version to re-encrypt the data. For more information about automatic key rotation, see Configure automatic key rotation.
  • The CMK that was used to encrypt your data remains unchanged, but EncryptionContext is changed. In this scenario, you can call this operation to re-encrypt the data.
  • You can call this operation to use a CMK in KMS to re-encrypt data or a data key that was previously encrypted by a different CMK.

To use the ReEncrypt operation, you must have two permissions:

  • kms:ReEncryptFrom on the source CMK
  • kms:ReEncryptTo on the destination CMK
  • For simplicity, you can specify kms:ReEncrypt* to allow both of the preceding permissions.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes ReEncrypt

The operation that you want to perform. Set the value to ReEncrypt.

CiphertextBlob String Yes ODZhOWVmZDktM2QxNi00ODk0LWJkNGYtMWZjNDNmM2YyYWJmS7FmDBBQ0BkKsQrtRnidtPwirmDcS0ZuJCU41xxAAWk4Z8qsADfbV0b+i6kQmlvj79dJdGOvtX69Uycs901q********

The ciphertext that you want to re-encrypt.

You can set this parameter to the ciphertext that is returned after a symmetric or asymmetric encryption operation.

DestinationKeyId String Yes 1234abcd-12ab-34cd-56ef-12345678****

The ID of the symmetric CMK that is used to re-encrypt the ciphertext after the ciphertext is decrypted.

SourceKeyId String No 5c438b18-05be-40ad-b6c2-3be6752c****

The ID of the CMK that is used to decrypt the ciphertext.

This parameter is the globally unique ID of the CMK.

Note If you set CiphertextBlob to the public key-encrypted ciphertext that is returned after an asymmetric encryption operation, specify this parameter.
SourceKeyVersionId String No 2ab1a983-7072-4bbc-a582-584b5bd8****

The ID of the CMK version that is used to decrypt the ciphertext.

Note If you set CiphertextBlob to the public key-encrypted ciphertext that is returned after an asymmetric encryption operation, specify this parameter.
SourceEncryptionAlgorithm String No RSAES_OAEP_SHA_256

The encryption algorithm based on which the public key is used to encrypt the ciphertext specified by CiphertextBlob. For more information about encryption algorithms, see AsymmetricDecrypt.

Valid values:

  • RSAES_OAEP_SHA_256
  • RSAES_OAEP_SHA_1
  • SM2PKE
Note If you set CiphertextBlob to the public key-encrypted ciphertext that is returned after an asymmetric encryption operation, specify this parameter.
SourceEncryptionContext Json No {"Example":"Example"}

A JSON string that consists of key-value pairs. If you specify EncryptionContext when you call the Encrypt, GenerateDataKey, GenerateDataKeyWithoutPlaintext, or GenerateAndExportDataKey operation to encrypt the data or data key, an equivalent value is required here. For more information, see EncryptionContext.

Note If you set CiphertextBlob to the ciphertext that is returned after a symmetric encryption operation, specify this parameter.
DestinationEncryptionContext Json No {"Example":"Example"}

A JSON string that consists of key-value pairs. This parameter specifies the EncryptionContext that is used to re-encrypt the decrypted data or data key.

Response parameters

Parameter Type Example Description
CiphertextBlob String DZhOWVmZDktM2QxNi00ODk0LWJkNGYtMWZjNDNmM2YyYWJmaaSl+TztSIMe43nbTH/Z1Wr4XfLftKhAciUmDQXuMRl4WTvKhxjMThjK****

The ciphertext re-encrypted.

KeyId String 2ab1a983-7072-4bbc-a582-584b5bd8****

The ID of the CMK that is used to decrypt the original ciphertext.

This parameter is the globally unique ID of the CMK.

KeyVersionId String 202b9877-5a25-46e3-a763-e20791b5****

The ID of the CMK version that is used to decrypt the original ciphertext.

RequestId String 207596a2-36d3-4840-b1bd-f87044699bd7

The ID of the request.

Examples

Sample requests

http(s)://[Endpoint]/?Action=ReEncrypt
&CiphertextBlob=ODZhOWVmZDktM2QxNi00ODk0LWJkNGYtMWZjNDNmM2YyYWJmS7FmDBBQ0BkKsQrtRnidtPwirmDcS0ZuJCU41xxAAWk4Z8qsADfbV0b+i6kQmlvj79dJdGOvtX69Uycs901q********
&DestinationKeyId=1234abcd-12ab-34cd-56ef-12345678****
&<Common request parameters>

Sample success responses

XML format

<KMS>
          <KeyId>202b9877-5a25-46e3-a763-e20791b5****</KeyId>
          <KeyVersionId>2ab1a983-7072-4bbc-a582-584b5bd8****</KeyVersionId>
          <CiphertextBlob>DZhOWVmZDktM2QxNi00ODk0LWJkNGYtMWZjNDNmM2YyYWJmaaSl+TztSIMe43nbTH/Z1Wr4XfLftKhAciUmDQXuMRl4WTvKhxjMThjK****</CiphertextBlob>
          <RequestId>4bd560a1-729e-45f1-a3d9-b2a33d61046b</RequestId>
</KMS>

JSON format

{
    "KeyId": "202b9877-5a25-46e3-a763-e20791b5****",
    "KeyVersionId": "2ab1a983-7072-4bbc-a582-584b5bd8****",
    "CiphertextBlob": "DZhOWVmZDktM2QxNi00ODk0LWJkNGYtMWZjNDNmM2YyYWJmaaSl+TztSIMe43nbTH/Z1Wr4XfLftKhAciUmDQXuMRl4WTvKhxjMThjK****",
    "RequestId": "4bd560a1-729e-45f1-a3d9-b2a33d61046b"
}

Error codes

HTTP status code Error code Error message Description
500 InternalFailure Internal Failure. The error message returned because an internal error has occurred. Try again later. If the error persists, submit a ticket.

For a list of error codes, visit the API Error Center.