Skip to content

生成数据密钥

生成一次性数据加密密钥,同时返回明文和由指定主密钥包裹的密文;明文只在本次响应中返回。

更新于 查看 Markdown
POST/api/v1/kms/keys/{key_id}/data-key
使用 App Header 签名或 App Secret需要 unsealed

Path 参数

key_id必填

string

密钥 ID

示例:"019fb1b5-7bb6-7eaf-9bf0-a1b2c3d4e5f6"

Body 参数

aad可选

string · sensitive

可选的无填充 Base64URL 编码附加认证数据(AAD)

示例:"b3JkZXI6MTAwMQ"

bits可选

int

数据加密密钥位数,只允许 128 或 256;省略时为 256

示例:256

成功响应

HTTP 200

操作成功

{
  "data": {
    "result": {
      "bits": 256,
      "ciphertext": "qk:v3:<opaque-ciphertext>",
      "plaintext": "<base64url-plaintext-key>",
      "wrapping_algorithm": "sm4-gcm",
      "wrapping_key_version": 3
    }
  },
  "error": null,
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

失败响应

按 HTTP status 和 error.code 区分失败原因;响应始终使用统一 envelope。

HTTP 400 · invalid_request

请求参数或 JSON 请求体无效

{
  "data": null,
  "error": {
    "code": "invalid_request",
    "details": {},
    "message": "请求参数或 JSON 请求体无效"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 400 · kms_purpose_mismatch

密钥用途不支持该操作

{
  "data": null,
  "error": {
    "code": "kms_purpose_mismatch",
    "details": {},
    "message": "密钥用途不支持该操作"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 400 · not_initialized

系统尚未初始化

{
  "data": null,
  "error": {
    "code": "not_initialized",
    "details": {},
    "message": "系统尚未初始化"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 401 · replayed_request

签名请求的 nonce 已被使用

{
  "data": null,
  "error": {
    "code": "replayed_request",
    "details": {},
    "message": "签名请求的 nonce 已被使用"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 401 · unauthorized

App ID、App Secret 或签名无效,或者凭据已过期

{
  "data": null,
  "error": {
    "code": "unauthorized",
    "details": {},
    "message": "App ID、App Secret 或签名无效,或者凭据已过期"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 403 · forbidden

App 没有访问目标资源所需的权限

{
  "data": null,
  "error": {
    "code": "forbidden",
    "details": {},
    "message": "App 没有访问目标资源所需的权限"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 404 · kms_key_not_found

密钥不存在

{
  "data": null,
  "error": {
    "code": "kms_key_not_found",
    "details": {},
    "message": "密钥不存在"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 409 · kms_key_disabled

密钥已禁用

{
  "data": null,
  "error": {
    "code": "kms_key_disabled",
    "details": {},
    "message": "密钥已禁用"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 409 · kms_key_retired

密钥已退役

{
  "data": null,
  "error": {
    "code": "kms_key_retired",
    "details": {},
    "message": "密钥已退役"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 413 · kms_input_too_large

输入数据超过 KMS 限制

{
  "data": null,
  "error": {
    "code": "kms_input_too_large",
    "details": {},
    "message": "输入数据超过 KMS 限制"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 413 · request_body_too_large

请求体超过服务端限制

{
  "data": null,
  "error": {
    "code": "request_body_too_large",
    "details": {},
    "message": "请求体超过服务端限制"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 423 · sealed

系统处于封印状态

{
  "data": null,
  "error": {
    "code": "sealed",
    "details": {},
    "message": "系统处于封印状态"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 500 · internal_error

服务端无法完成请求

{
  "data": null,
  "error": {
    "code": "internal_error",
    "details": {},
    "message": "服务端无法完成请求"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 503 · crypto_unavailable

密码服务暂不可用

{
  "data": null,
  "error": {
    "code": "crypto_unavailable",
    "details": {},
    "message": "密码服务暂不可用"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 503 · leader_unavailable

高可用集群的 Leader 暂不可用

{
  "data": null,
  "error": {
    "code": "leader_unavailable",
    "details": {},
    "message": "高可用集群的 Leader 暂不可用"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}

HTTP 503 · maintenance_mode

系统处于维护模式

{
  "data": null,
  "error": {
    "code": "maintenance_mode",
    "details": {},
    "message": "系统处于维护模式"
  },
  "request_id": "019fb18d-6b45-7e2d-a3b4-c5d6e7f80910"
}
Navigation

Type to search…

↑↓ navigate↵ selectEsc close