You need to enable JavaScript to run this app.
文档中心
密钥管理系统

密钥管理系统

复制全文
下载 pdf
密钥管理
CreateKey - 创建用户主密钥
复制全文
下载 pdf
CreateKey - 创建用户主密钥

调用本接口在指定密钥环下创建新的用户主密钥(CMK),用于后续的数据加密、解密、签名验签或 MAC 计算等操作。

调试

请求参数

下表仅列出该接口特有的请求参数和部分公共参数。更多信息请见公共参数。

参数
类型
是否必填
示例值
描述
Action
String
是

CreateKey

要执行的操作,取值:CreateKey。

Version
String
是

2021-02-18

API的版本,取值:2021-02-18。

KeyringName
String
是

keyring-test

密钥环名称
长度为 2 - 31 个字符
合法字符:[a-zA-Z0-9-_]

KeyName
String
是

key-test

主密钥名称
长度为 2 - 31 个字符
合法字符:[a-zA-Z0-9-_]

KeySpec
String
否

SYMMETRIC_256

密钥规格,默认值:SYMMETRIC_256。对称密钥:SYMMETRIC_256、SYMMETRIC_128。非对称密钥:RSA_2048、RSA_3072、RSA_4096、EC_P256、EC_P256K、EC_P384、EC_P521、EC_SM2。

Description
String
否

test

密钥描述
长度为 0 - 8192 个字符

KeyUsage
String
否

ENCRYPT_DECRYPT

密钥用途。取值:ENCRYPT_DECRYPT(加密和解密)、SIGN_VERIFY(签名和验签)、GENERATE_VERIFY_MAC(生成和验证消息认证码)。 默认值:ENCRYPT_DECRYPT。

ProtectionLevel
String
否

SOFTWARE

密钥保护级别。取值:SOFTWARE(软件保护)、HSM(硬件安全模块保护)。 默认值:SOFTWARE。

RotateState
String
否

Enable

密钥轮转状态。取值:Enable(开启自动轮转)、Disable(关闭自动轮转)。默认值:Enable。

RotateInterval
Integer
否

365

密钥轮转周期,单位:天;取值范围:[90, 2560]。默认值:365。

Origin
String
否

CloudKMS

密钥来源。取值:CloudKMS(KMS 生成密钥材料)、External(外部导入密钥材料)、ExternalKeyStore(外部密钥存储)。 默认值:CloudKMS。

MultiRegion
Boolean
否

false

是否创建多地域类型的主密钥。true:创建多地域密钥;false:创建单地域密钥。默认值:false。

Tags
Array of Object
否

[{"Key":"region","Value":"cn-shanghai"}]

为资源绑定的标签列表,用于资源分类和管理。不传时默认不绑定任何标签。

CustomKeyStoreID
String
否

f8cd8bcd-6a50-46e7-805a-be4f37ac8b1c

自定义密钥存储 ID,长度为 36 个字符。合法字符:[a-zA-Z0-9-]。可通过 CreateCustomKeyStore 创建自定义密钥存储时返回,或通过 DescribeCustomKeyStores 查询获取。不传时默认不使用自定义密钥存储。

XksKeyID
String
否

1b52c08e-e8d1-4831-a4c3-e142a6733330

外部密钥存储密钥 ID,长度为 1 - 128 个字符。合法字符:[a-zA-Z0-9-_.]。可在外部密钥存储中创建或查询获取。不传时默认不绑定外部密钥存储密钥。

返回参数

下表仅列出本接口特有的返回参数。更多信息请参见返回结构。

参数
类型
示例值
描述
Key
Object

Key 结构的数据

主密钥信息

请求示例

GET /?Action=CreateKey&Version=2021-02-18&KeyringName=demo&KeyName=demo&KeySpec=SYMMETRIC_256&Description=demo&KeyUsage=ENCRYPT_DECRYPT&ProtectionLevel=SOFTWARE&RotateState=Enable&Origin=CloudKMS HTTP/1.1
Host: kms.cn-beijing.volcengineapi.com
X-Date: 20240707T150834Z
Authorization: HMAC-SHA256 Credential=Adfks******wekfwe/20240707/cn-beijing/kms/request, SignedHeaders=host;x-date, Signature=47a7d934ff7b37c03938******cd7b8278a40a1057690c401e92246a0e41085f


返回示例

{
  "ResponseMetadata": {
    "RequestId": "20240707231112068082115004555B91",
    "Action": "CreateKey",
    "Version": "2021-02-18",
    "Service": "kms",
    "Region": "cn-beijing"
  },
  "Result": {
    "Key": {
      "ID": "d24a9f14-1a8b-4393-b66e-b77b766b5735",
      "CreationDate": 1625818017,
      "UpdateDate": 1625818017591,
      "KeyName": "demo",
      "KeySpec": "SYMMETRIC_256",
      "Description": "demo",
      "KeyState": "Enable",
      "KeyUsage": "ENCRYPT_DECRYPT",
      "ProtectionLevel": "SOFTWARE",
      "Origin": "CloudKMS",
      "MultiRegion": false
    }
  }
}

错误码

下表为您列举了该接口与业务逻辑相关的错误码。公共错误码请参见公共错误码文档。

状态码
错误码
错误信息
说明
400
InvalidParameter

The request parameter %s is invalid.

请求参数格式、类型或取值不合法,请根据参数说明检查并修正请求。

400
InvalidOperation

The request was rejected because the specified resource is not valid for this operation.

指定资源或当前状态不支持该操作,请确认操作对象和调用时机。

400
MissingParameter

The request is missing %s parameter.

缺少必填参数,请根据接口请求参数说明补充后重试。

400
XksProxyInvalidUriPath

The external key store proxy rejected the request because of an invalid URI path. Verify the URI path for your external key store and update if necessary.

外部密钥存储或相关资源配置不满足当前操作要求,请检查资源状态、网络连通性、认证凭据和参数配置后重试。

400
XksProxyInvalidResponse

CloudKMS cannot interpret the response from the external key store proxy. If you see this error repeatedly, report it to your external key store proxy administrator.

外部密钥存储或相关资源配置不满足当前操作要求,请检查资源状态、网络连通性、认证凭据和参数配置后重试。

400
CustomKeyStoreInvalidState

The request was rejected because of the ConnectionState of the custom key store. To get the ConnectionState of a custom key store, use the DescribeCustomKeyStores operation.

外部密钥存储或相关资源配置不满足当前操作要求,请检查资源状态、网络连通性、认证凭据和参数配置后重试。

400
XksProxyUriUnreachable

The external key store proxy is in an unhealthy state. If you see this message repeatedly, notify your external key store proxy administrator.

外部密钥存储或相关资源配置不满足当前操作要求,请检查资源状态、网络连通性、认证凭据和参数配置后重试。

400
XksProxyIncorrectAuthenticationCredential

The external key store proxy rejected the request because it could not authenticate CloudKMS. Verify the XKS proxy authentication credentials for your external key store and update if necessary.

外部密钥存储或相关资源配置不满足当前操作要求,请检查资源状态、网络连通性、认证凭据和参数配置后重试。

403
AccessDenied

User is not authorized to do this action

当前账号或子账号缺少执行该操作所需权限,请检查 IAM 授权策略。

403
Reject.Throttling.Action

The request of Action: %s upper limit is exceeded.

接口级请求频率超过限制,请降低请求速率后重试。

403
KeyLimitExceeded

"The request was rejected because it would exceed the key quota. Current key quota is %d, limit

密钥数量超过配额限制,请删除不再使用的密钥或申请提升配额。

403
XksProxyAccessDenied

The external key store proxy denied access to the operation. Verify that the user and the external key are both authorized for this operation, and try the request again.

外部密钥存储或相关资源配置不满足当前操作要求,请检查资源状态、网络连通性、认证凭据和参数配置后重试。

403
KMS_ServiceNotOpen

KMS service not open yet, please open the service and try again later.

KMS 服务尚未开通,请先在控制台开通服务后重试。

404
Not Found

Not found %s [%s].

指定资源不存在或当前账号无权访问,请检查资源 ID、名称和地域是否正确。

409
Conflict

The %s resource %s is conflict.

资源已存在或当前操作与已有资源状态冲突,请检查后重试。

409
ProjectConflict

The secret [%s] already exists in one project.

资源已存在于指定项目或与项目内已有资源冲突,请检查项目和资源名称。

500
UndefinedError

Undefined Internal Error. Pls Contact With Admin.

服务内部错误,请稍后重试;如持续出现,请联系技术支持。

最近更新时间:2026.09.03 18:00:32
这个页面对您有帮助吗?
有用
有用
无用
无用