Last updated: 2019-12-14 11:56:42

1. API Description

API domain name: kms.tencentcloudapi.com

This API encrypts maximum 4 KB of data. Such data includes database passwords, RSA keys, or other sensitive information. You can also apply DataKey generated by API GenerateDataKey to encrypt or decrypt your local data.

API request rate limit: 300 requests/sec.

2. Input Parameters

The list below contains only the API request parameters and certain common parameters. For the complete common parameter list, see Common Request Parameters.

Parameter name Required Type Description
Action Yes String Common parameter. The value used for this API: Encrypt
Version Yes String Common parameter. The version of this API: 2019-01-18
Region Yes String Common parameter. For more information, 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 allowed for original data is 4 KB
EncryptionContext No String key-value pair JSON string. If this parameter is specified for Encrypt, the same parameter needs to be provided to call API Decrypt. The maximum value allowed is 1,024 characters

3. Output Parameters

Parameter name Type Description
CiphertextBlob String Encrypted ciphertext
KeyId String Globally unique ID of the CMK used for encryption
RequestId String Unique ID of the request. Each request returns a unique ID. The RequestId is required to troubleshoot issues.

4. Examples

Example 1. Encrypting

Use a CMK to encrypt up to 4 KB of data.

Input Sample Code

&<Common request parameter>

Output Sample Code

  "Response": {
    "RequestId": "816c6886-2147-4ee7-86f0-9400a7a398a5",
    "KeyId": "9999aed0-4956-11e9-bc70-5254005e86b4",
    "CiphertextBlob": "g2F8eQk44QrTbfj09TL17AZyFPgs8BTtZe2j27Wuw1YzTBCxnd0T/gwFQSasmtzxZi6mmvD7DCjCE+LxJmdhXQ==-k-zJshb0kBH7C2J5I3XXbbEg==-k-o1O+7H9HFAzWbCkftO2ZtPKewS3diSB4zGKOJhMn7LcKRhYr"

5. Developer Resources

API Explorer

*This tool makes it easy for you to call Tencent Cloud APIs, authenticate signature, generate SDK codes, and search for APIs. *

6. Error Codes

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

Error Code Description
InternalError Internal error.
InvalidParameter Incorrect parameter.
InvalidParameterValue.InvalidKeyId Invalid KeyId.
InvalidParameterValue.InvalidPlaintext Invalid plaintext.
ResourceUnavailable.CmkDisabled The CMK has been disabled.
ResourceUnavailable.CmkNotFound The CMK does not exist.
UnauthorizedOperation Unauthorized operation.