tencent cloud

Encrypt
Last updated: 2025-12-04 15:44:15
Encrypt
Last updated: 2025-12-04 15:44:15

1. API Description

Domain name for API request: kms.intl.tencentcloudapi.com.

This API is used to encrypt any data up to 4KB. It can be used to encrypt database passwords, RSA Key, or other small sensitive information. For application data encryption, use the DataKey generated by GenerateDataKey to perform local data encryption and decryption operations

A maximum of 300 requests can be initiated per second for this API.

We recommend you to use API Explorer
Try it
API Explorer provides a range of capabilities, including online call, signature authentication, SDK code generation, and API quick search. It enables you to view the request, response, and auto-generated examples.

2. Input Parameters

The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

Parameter Name Required Type Description
Action Yes String Common Params. The value used for this API: Encrypt.
Version Yes String Common Params. The value used for this API: 2019-01-18.
Region Yes String Common Params. For more information, please see the list of regions supported by the product.
KeyId Yes String Globally unique ID of the CMK generated by calling the CreateKey API
Plaintext Yes String Encrypted plaintext data. This field must be Base64-encoded. The maximum size of the original data is 4 KB
EncryptionContext No String JSON string of key-value pair. If this parameter is specified, the same parameter needs to be provided when the Decrypt API is called. It is up to 1,024 characters

3. Output Parameters

Parameter Name Type Description
CiphertextBlob String Base64-encoded ciphertext, which is the encrypted information of the ciphertext and key. To get the plaintext, you need to pass in this field to the Decrypt API.
KeyId String Globally unique ID of the CMK used for encryption
RequestId String The unique request ID, generated by the server, will be returned for every request (if the request fails to reach the server for other reasons, the request will not obtain a RequestId). RequestId is required for locating a problem.

4. Example

Example1 Example of Encryption API

This example shows you how to encrypt data less than 4 KB in size using a CMK.

Input Example

POST / HTTP/1.1
Host: kms.intl.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: Encrypt
<Common request parameters>

{
    "KeyId": "93866e69-9755-11ef-8e65-52540089bc41",
    "Plaintext": "dGVzdAo=",
    "EncryptionContext": "{\"key1\":\"value1\"}"
}

Output Example

{
    "Response": {
        "CiphertextBlob": "GPJUsGlmPcSjHKIktXGyzn33yestz+7NteW36M6FuL8hPfJ1xVfdO6Akr8sF69x3yBXMwto4njumJMIsi9WKow==-k-XqqalxTyNKIC1rITRePFGQ==-k-GqsANzNxvjjXhKwJAOY85vxYYm/2RtsCXRq7Q1iWbCAoeAtZ",
        "KeyId": "93866e69-9755-11ef-8e65-52540089bc41",
        "RequestId": "017f4b2a-4ae8-4d2c-a0d2-ec15e07d3deb"
    }
}

5. Developer Resources

SDK

TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

Command Line Interface

6. Error Code

The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

Error Code Description
InternalError Internal error.
InvalidParameter Invalid parameter.
InvalidParameterValue.InvalidKeyId Invalid KeyId.
InvalidParameterValue.InvalidPlaintext Invalid Plaintext.
ResourceUnavailable.CmkArchived The CMK has been archived.
ResourceUnavailable.CmkDisabled The CMK has been disabled.
ResourceUnavailable.CmkNotFound The CMK does not exist.
UnauthorizedOperation Unauthorized operation.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback