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

密钥管理系统

复制全文
下载 pdf
密钥管理
Encrypt - 对称加密
复制全文
下载 pdf
Encrypt - 对称加密

调用本接口使用指定的 KMS 对称密钥对 Base64 编码的明文数据进行加密,并返回密文。

调试

请求参数

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

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

Encrypt

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

Version
String
是

2021-02-18

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

KeyringName
String
否

keyring-test

密钥环名称,长度为 2 - 31 个字符。合法字符:[a-zA-Z0-9-_]。可通过 CreateKeyring 创建密钥环时指定,或通过 DescribeKeyrings、QueryKeyring 查询获取。当不指定 KeyID 时,必须与 KeyName 同时传入;与 KeyID 二选一。

KeyName
String
否

key-test

主密钥名称,长度为 2 - 31 个字符。合法字符:[a-zA-Z0-9-_]。可通过 CreateKey 创建密钥时指定,或通过 DescribeKeys、DescribeKey 查询获取。当不指定 KeyID 时,必须与 KeyringName 同时传入;与 KeyID 二选一。

KeyID
String
否

0324d9b3-c5d9-4b6f-94e7-884010a16fee

主密钥 ID,UUID 形式。可通过 CreateKey 创建密钥时返回,或通过 DescribeKeys、DescribeKey 查询获取。KeyID 与 KeyringName + KeyName 二选一;传入 KeyID 时无需传入 KeyringName 和 KeyName;未传入 KeyID 时,必须同时传入 KeyringName 和 KeyName。

EncryptionContext
String
否

{"user":"alice","path":"path/to/alice/plaintext.txt"}

key/value 的 JSON 字符串,用作加密上下文。在调用 Encrypt 加密时如果指定了该参数,则调用 Decrypt 解密时需要提供完全相同的参数;不传时默认不使用加密上下文进行校验。

Plaintext
String
是

tWB54tTvEu47YjRjuuj+fAt5PskpUaqwsjLeEy4YMNg=

待加密的明文,Base64 编码,长度范围为 1 到 4096 字节。

返回参数

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

参数
类型
示例值
描述
CiphertextBlob
String

43y7grE9TjamX4P7ZOHFbwAAqoNHFtMZ6RNyblKlEhIhrfP6zy034cwJN6MSqFGiDm8oiGqu2Rahs1aKPIcMjaOuodVCE1zYpDFg1QvgOHtVQxkQWhfpE8i8NibiJ1pL8ILgAE+TogQZuIglAoo=

明文加密后的密文,Base64编码

请求示例

POST /?Action=Encrypt&Version=2021-02-18&KeyringName=demo&KeyName=demo HTTP/1.1
Host: kms.cn-beijing.volcengineapi.com
Content-Type: application/json; charset=UTF-8
X-Date: 20240708T064450Z
X-Content-Sha256: 287e874e******d653b44d21e
Authorization: HMAC-SHA256 Credential=Adfks******wekfwe/20240708/cn-beijing/kms/request, SignedHeaders=host;x-content-sha256;x-date, Signature=47a7d934ff7b37c03938******cd7b8278a40a1057690c401e92246a0e41085f

{
  "Plaintext": "tWB54tTvEu47YjRjuuj+fAt5PskpUaqwsjLeEy4YMNg="
}

返回示例

{
  "ResponseMetadata": {
    "RequestId": "202407081445581770951421937A1E35",
    "Action": "Encrypt",
    "Version": "2021-02-18",
    "Service": "kms",
    "Region": "cn-beijing"
  },
  "Result": {
    "CiphertextBlob": "43y7grE9TjamX4P7ZOHFbwAAqoNHFtMZ6RNyblKlEhIhrfP6zy034cwJN6MSqFGiDm8oiGqu2Rahs1aKPIcMjaOuodVCE1zYpDFg1QvgOHtVQxkQWhfpE8i8NibiJ1pL8ILgAE+TogQZuIglAoo="
  }
}

错误码

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

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

The request parameter %s is invalid.

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

400
MissingParameter

The request is missing %s parameter.

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

400
InvalidKeyStatus

Current key status: %s does not allow to perform this action

当前密钥状态不支持执行该操作,请检查密钥是否处于接口要求的状态。

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.

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

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
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
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.

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

403
AccessDenied

User is not authorized to do this action

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

403
Reject.Throttling.CMK

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

指定主密钥的请求频率超过限制,请降低该密钥相关请求速率后重试。

403
KeyMaterialExpire

Key expire in, %s

密钥材料已过期或不可用,请重新导入有效密钥材料后重试。

403
KMS_ServiceNotOpen

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

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

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.

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

404
Not Found

Not found %s [%s].

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

500
UndefinedError

Undefined Internal Error. Pls Contact With Admin.

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

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