All Products
Search
Document Center

Key Management Service:ReEncrypt

Last Updated:Sep 09, 2024

Re-encrypts ciphertext. When you call this operation, Key Management Service (KMS) decrypts the ciphertext, uses a different key to re-encrypt the generated plaintext or data key, and then returns the new ciphertext.

Usage notes

  • Keys outside Key Management Service (KMS) instances: To perform cryptographic operations, use Alibaba Cloud SDK to call operations.
  • Keys in KMS instances: To perform cryptographic operations, use one of the following methods:

Limits

You can call this operation up to 750 times per second per account. If the number of calls per second exceeds the limit, throttling is triggered. As a result, your business may be affected. We recommend that you take note of the limit when you call this operation.

Description

You can call this operation in the following scenarios:

  • After a key that was used to encrypt your data is rotated, you can call this operation to use the latest key version to re-encrypt the data. For more information about automatic key rotation, see Configure automatic key rotation.
  • The key 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 key in KMS to re-encrypt data or a data key that was previously encrypted by using a different key.

To call the ReEncrypt operation, you must have the following permissions:

  • The kms:ReEncryptFrom permission on the source key
  • The kms:ReEncryptTo permission on the destination key
  • 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 symmetric or asymmetric encryption.

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

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

The ID must be globally unique.

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

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

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

The encryption algorithm that is used by the public key when CiphertextBlob is set to the public key-encrypted ciphertext. 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 asymmetric encryption, specify this parameter.
SourceEncryptionContext Map No {"Example":"Example"}

The JSON string that consists of key-value pairs. If you specify this parameter when you call the Encrypt, GenerateDataKey, GenerateDataKeyWithoutPlaintext, or GenerateAndExportDataKey operation, you must specify the same value for this parameter when you call the ReEncrypt operation. For more information, see EncryptionContext.

Note If you set CiphertextBlob to the ciphertext that is returned after symmetric encryption, specify this parameter.
DestinationKeyId String Yes 1234abcd-12ab-34cd-56ef-12345678****

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

DestinationEncryptionContext Map No {"Example":"Example"}

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

DryRun String No false

Specifies whether to perform a dry run. Valid values:

  • true
  • false (default)

A dry run is used for testing in API calls. You can perform a dry run to check whether you have the permissions to access the resources that you want to manage and whether the request parameters are correctly configured. If you set DryRun to true in the request, KMS always returns an error code that indicates the cause of the error. KMS may return the following error codes:

  • DryRunOperationError: The request passes the dry run. If you do not specify the DryRun parameter and retain the other parameter configurations to call the same operation, the operation will be performed.
  • ValidationError: A parameter value in the request is invalid.
  • AccessDeniedError: You do not have the permissions to access the resources that you want to manage.

Response parameters

Parameter

Type

Example

Description

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

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

The ID must be globally unique.

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

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

CiphertextBlob String DZhOWVmZDktM2QxNi00ODk0LWJkNGYtMWZjNDNmM2YyYWJmaaSl+TztSIMe43nbTH/Z1Wr4XfLftKhAciUmDQXuMRl4WTvKhxjMThjK****

The new ciphertext.

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

The request ID.

Examples

Sample requests

http(s)://[Endpoint]/?Action=ReEncrypt
&CiphertextBlob=ODZhOWVmZDktM2QxNi00ODk0LWJkNGYtMWZjNDNmM2YyYWJmS7FmDBBQ0BkKsQrtRnidtPwirmDcS0ZuJCU41xxAAWk4Z8qsADfbV0b+i6kQmlvj79dJdGOvtX69Uycs901q********
&SourceKeyId=5c438b18-05be-40ad-b6c2-3be6752c****
&SourceKeyVersionId=2ab1a983-7072-4bbc-a582-584b5bd8****
&SourceEncryptionAlgorithm=RSAES_OAEP_SHA_256
&DestinationKeyId=1234abcd-12ab-34cd-56ef-12345678****
&DryRun=false
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<ReEncryptResponse>
    <KeyId>2ab1a983-7072-4bbc-a582-584b5bd8****</KeyId>
    <KeyVersionId>202b9877-5a25-46e3-a763-e20791b5****</KeyVersionId>
    <CiphertextBlob>DZhOWVmZDktM2QxNi00ODk0LWJkNGYtMWZjNDNmM2YyYWJmaaSl+TztSIMe43nbTH/Z1Wr4XfLftKhAciUmDQXuMRl4WTvKhxjMThjK****</CiphertextBlob>
    <RequestId>207596a2-36d3-4840-b1bd-f87044699bd7</RequestId>
</ReEncryptResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "KeyId" : "2ab1a983-7072-4bbc-a582-584b5bd8****",
  "KeyVersionId" : "202b9877-5a25-46e3-a763-e20791b5****",
  "CiphertextBlob" : "DZhOWVmZDktM2QxNi00ODk0LWJkNGYtMWZjNDNmM2YyYWJmaaSl+TztSIMe43nbTH/Z1Wr4XfLftKhAciUmDQXuMRl4WTvKhxjMThjK****",
  "RequestId" : "207596a2-36d3-4840-b1bd-f87044699bd7"
}

Error codes

HttpCode

Error code

Error message

Description

400 InvalidParameter The specified parameter is not valid. The specified parameter is invalid.
404 Forbidden.KeyNotFound The specified Key is not found. The specified key does not exist.
500 InternalFailure Internal Failure. An internal error occurred. Try again later. If the error persists, submit a ticket.

For a list of error codes, see Service error codes.