tencent cloud

APIs

CreateKey

다운로드
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-11-16 17:51:58

1. API Description

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

Create a master key CMK (Custom Master Key) for user management data keys

A maximum of 100 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: CreateKey.
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.
Alias Yes String

Alias that makes the key easier to identify and understand. It cannot be empty and must contain 1-60 alphanumeric characters, hyphens (-), or underscores (_), and start with a letter or digit. Aliases prefixed with kms- are reserved for cloud services. The alias must be unique.

Description No String

Description of the CMK. Maximum length: 1024 bytes.

KeyUsage No String

Specifies the purpose of the key. The default value is "ENCRYPT_DECRYPT", which indicates creating a symmetric encryption/decryption key. Other supported purposes: "ASYMMETRIC_DECRYPT_RSA_2048" indicates creating an RSA2048 asymmetric key for encryption/decryption; "ASYMMETRIC_DECRYPT_RSA_3072" indicates creating an RSA3072 asymmetric key for encryption/decryption; "ASYMMETRIC_DECRYPT_RSA_4096" indicates creating an RSA4096 asymmetric key for encryption/decryption; "ASYMMETRIC_DECRYPT_SM2" indicates creating an SM2 asymmetric key for encryption/decryption; "ASYMMETRIC_SIGN_VERIFY_SM2" indicates creating an SM2 asymmetric key for signature generation and verification; "ASYMMETRIC_SIGN_VERIFY_ECC" indicates creating an ECC asymmetric key for signature generation and verification; "ASYMMETRIC_SIGN_VERIFY_RSA_2048" indicates creating an RSA_2048 asymmetric key for signature generation and verification; "ASYMMETRIC_SIGN_VERIFY_RSA_3072" indicates creating an RSA_3072 asymmetric key for signature generation and verification;
"ASYMMETRIC_SIGN_VERIFY_RSA_4096" indicates creating an RSA_4096 asymmetric key for signature generation and verification; "ASYMMETRIC_SIGN_VERIFY_ECDSA384" indicates creating an ECDSA384 asymmetric key for signature generation and verification. For the complete list of key purposes and supported algorithms, call the ListAlgorithms API.

Type No Integer

Specifies the key type. The default value is 1. 1 indicates the default type, where the CMK is created by KMS. 2 indicates the EXTERNAL type, where you need to import the key material. For more information, see the GetParametersForImport and ImportKeyMaterial APIs.

Tags.N No Array of Tag

Tag list.

HsmClusterId No String

HSM cluster ID corresponding to KMS Advanced Edition (valid only for KMS exclusive/managed service instances).

3. Output Parameters

Parameter Name Type Description
KeyId String

Globally unique identifier of the CMK

Alias String

Alias that makes the key easier to identify and understand

CreateTime Integer

Key creation time, unix timestamp

Description String

Description of the CMK

KeyState String

Status of the CMK

KeyUsage String

Purpose of the CMK

TagCode Integer

Return code of the tag operation. 0: Success; 1: Internal error; 2: Business processing error

TagMsg String

Return message of the tag operation

HsmClusterId String

HSM cluster ID (valid only for KMS exclusive/managed service instances)

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 Creating a CMK Example

This example shows you how to create a Custom Master Key (CMK) for user-managed DEKs. Subsequently, you can call other APIs such as creating DEKs and performing encryption and decryption operations.

Input Example

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

{
"Description": "test Description"
    "Alias": "test8-lzc",
    "KeyUsage": "ENCRYPT_DECRYPT",
    "Type": 1,
    "Tags": [
        {
            "TagKey": "env",
            "TagValue": "dev"
        }
    ]
}

Output Example

{
    "Response": {
        "Alias": "test8-lzc",
        "CreateTime": 1730347170,
"Description": "test description"
        "HsmClusterId": "cls-hsm-3dflmo9g",
        "KeyId": "87ff856e-973c-11ef-947b-525400d834e5",
        "KeyState": "Enabled",
        "KeyUsage": "ENCRYPT_DECRYPT",
        "RequestId": "c44aba41-015a-45aa-9e55-1a08ac9d1d78",
        "TagCode": 0,
        "TagMsg": "ok"
    }
}

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
FailedOperation.TaggingError Tagging error.
InternalError Internal error.
InvalidParameter Invalid parameter.
InvalidParameterValue.AliasAlreadyExists The alias already exists.
InvalidParameterValue.InvalidAlias Incorrect alias format
InvalidParameterValue.InvalidHsmClusterId Invalid HSM cluster ID.
InvalidParameterValue.InvalidKeyUsage Incorrect KeyUsage parameter.
InvalidParameterValue.InvalidType Incorrect Type parameter.
InvalidParameterValue.TagKeysDuplicated Duplicate tag key.
InvalidParameterValue.TagsNotExisted The tag key or tag value does not exist.
LimitExceeded.CmkLimitExceeded The number of CMKs has reached the upper limit.
UnauthorizedOperation Unauthorized operation.
UnsupportedOperation.ServiceTemporaryUnavailable The service is temporarily unavailable.
UnsupportedOperation.UnsupportedKeyUsageInCurrentRegion The encryption method is not supported in the current region.
UnsupportedOperation.UserVersionNotSupport Unsupported user version.

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백