数据加密服务 DEW-示例2:加解密大量数据:操作步骤

时间:2023-11-01 16:21:51

操作步骤

  1. 创建用户主密钥。

    • 接口相关信息

      URI格式:POST /v1.0/{project_id}/kms/create-key

      详情请参见创建密钥

      别名“/default”为服务默认主密钥的后缀名,由服务自动创建。因此用户创建的主密钥别名不能与服务默认主密钥的别名相同,即后缀名不能为“/default”

    • 请求示例

      POST: https://{endpoint}/v1.0/53d1aefc533f4ce9a59c26b01667cbcf/kms/create-key

      {endpoint}信息请从地区和终端节点获取。

      Body:

      {    "key_alias": "test"}
    • 响应示例
      {    "key_info": {        "key_id": "bb6a3d22-dc93-47ac-b5bd-88df7ad35f1e",        "domain_id": "b168fe00ff56492495a7d22974df2d0b"    }}

  2. 创建数据密钥。

    • 接口相关信息

      URI格式:POST /v1.0/{project_id}/kms/create-datakey

      详情请参见创建数据密钥

    • 请求示例

      POST https://{endpoint}/v1.0/53d1aefc533f4ce9a59c26b01667cbcf/kms/create-datakey

      {endpoint}信息请从地区和终端节点获取。

      您可使用查询密钥列表接口获取当前用户密钥列表,包括key_id等信息 。

      Body:

      {    "key_id": "0d0466b0-e727-4d9c-b35d-f84bb474a37f",    "datakey_length": "512"}
    • 响应示例
      {    "key_id": "0d0466b0-e727-4d9c-b35d-f84bb474a37f",    "plain_text": "8151014275E426C72EE7D44267EF11590DCE0089E19863BA8CC832187B156A72A5A17F17B5EF0D525872C59ECEB72948AF85E18427F8BE0D46545C979306C08D",    "cipher_text": "020098009EEAFCE122CAA5927D2E020086F9548BA1675FDB022E4ECC01B96F2189CF4B85E78357E73E1CEB518DAF7A4960E7C7DE8885ED3FB2F1471ABF400119CC1B20BD3C4A9B80AF590EFD0AEDABFDBB0E2B689DA7B6C9E7D3C5645FCD9274802586BE63779471F9156F2CDF07CD8412FFBE9230643034363662302D653732372D346439632D623335642D6638346262343734613337660000000045B05321483BD9F9561865EE7DFE9BE267A42EB104E98C16589CE46940B18E52"}

  3. 加密数据密钥。

    • 接口相关信息

      URI格式:POST /v1.0/{project_id}/kms/encrypt-datakey

      详情请参见加密数据密钥

    • 请求示例

      POST https://{endpoint}/v1.0/53d1aefc533f4ce9a59c26b01667cbcf/kms/encrypt-datakey

      {endpoint}信息请从地区和终端节点获取。

      您可使用查询密钥列表接口获取当前用户密钥列表,包括key_id等信息 。

      Body:

      {    "key_id": "0d0466b0-e727-4d9c-b35d-f84bb474a37f",    "plain_text": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F5A5FD42D16A20302798EF6ED309979B43003D2320D9F0E8EA9831A92759FB4B",    "datakey_plain_length": "64"}
    • 响应示例
      {    "key_id": "0d0466b0-e727-4d9c-b35d-f84bb474a37f",    "cipher_text": "020098005273E14E6E8E95F5463BECDC27E80AF820B9FC086CB47861899149F67CF07DAFF2810B7D27BDF19AB7632488E0926A48DB2FC85BEA905119411B46244C5E6B8036C60A0B0B4842FFE6994518E89C19B1C1D688D9043BCD6053EA7BA0652642CE59F2543C80669139F4F71ABB9BD9A24330643034363662302D653732372D346439632D623335642D66383462623437346133376600000000D34457984F9730D57F228C210FD22CA6017913964B21D4ECE45D81092BB9112E",    "datakey_length": "64"}

  4. 解密数据密钥。

    • 接口相关信息

      URI格式:POST /v1.0/{project_id}/kms/decrypt-datakey

      详情请参见解密数据密钥

    • 请求示例

      POST https://{endpoint}/v1.0/53d1aefc533f4ce9a59c26b01667cbcf/kms/decrypt-datakey

      {endpoint}信息请从地区和终端节点获取。

      您可使用查询密钥列表接口获取当前用户密钥列表,包括key_id等信息 。

      Body:

      {    "key_id": "0d0466b0-e727-4d9c-b35d-f84bb474a37f",    "datakey_cipher_length": "64",    "cipher_text": "020098005273E14E6E8E95F5463BECDC27E80AF820B9FC086CB47861899149F67CF07DAFF2810B7D27BDF19AB7632488E0926A48DB2FC85BEA905119411B46244C5E6B8036C60A0B0B4842FFE6994518E89C19B1C1D688D9043BCD6053EA7BA0652642CE59F2543C80669139F4F71ABB9BD9A24330643034363662302D653732372D346439632D623335642D66383462623437346133376600000000D34457984F9730D57F228C210FD22CA6017913964B21D4ECE45D81092BB9112E"}
    • 响应示例
      {    "data_key": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",    "datakey_length": "64",    "datakey_dgst": "F5A5FD42D16A20302798EF6ED309979B43003D2320D9F0E8EA9831A92759FB4B"}

support.huaweicloud.com/api-dew/dew_02_0318.html