建立匯入記號

您可以先建立 IBM Cloud® Hyper Protect Crypto Services 服務實例的匯入記號,以啟用將根金鑰資料安全匯入至雲端。

匯入記號是用來根據您指定的原則,將根金鑰資料加密並安全地帶入 Hyper Protect Crypto Services。 若要進一步瞭解如何將金鑰安全地匯入至雲端中,請參閱自帶加密金鑰到雲端

使用 API 建立匯入記號

對下列端點發出 POST 呼叫,以建立與 Hyper Protect Crypto Services 服務實例相關聯的匯入記號。

https://<instance_ID>.api.<region>.hs-crypto.appdomain.cloud/api/v2/import_token
  1. 擷取服務及鑑別認證以在服務中使用金鑰

  2. 呼叫 金鑰管理服務 API來設定匯入記號的原則。

    curl -X POST \
      https://<instance_ID>.api.<region>.hs-crypto.appdomain.cloud/api/v2/import_token \
      -H 'authorization: Bearer <IAM_token>' \
      -H 'bluemix-instance: <instance_ID>' \
      -H 'content-type: application/json' \
      -d '{
     "expiration": <expiration_time>,  \
     "maxAllowedRetrievals": <use_count>  \
    }'
    

    根據下表取代範例要求中的變數。

    表 1. 說明使用 API 建立匯入記號所需的變數
    變數 說明
    區域 必要。 代表 Hyper Protect Crypto Services 服務實例所在地理區域的地區縮寫,例如 us-southau-syd。 如需相關資訊,請參閱地區服務端點
    連接埠 必要。 API 端點的埠號。
    IAM_token 必要。 您的 IBM Cloud 存取記號。 請在 cURL 要求中包含 IAM 記號的完整內容,包括 Bearer 值。 如需相關資訊,請參閱 擷取存取記號
    instance_id 必要。 指派給您 Hyper Protect Crypto Services 服務實例的唯一 ID。 如需相關資訊,請參閱 擷取實例 ID
    expiration_time 從建立匯入記號開始的時間 (以秒為單位),決定它保持有效的時間長度。 最小值是 300 秒(5 分鐘),最大值是 86400 秒(24 小時)。 預設值是 600 秒(10 分鐘)。
    use_count 在無法再存取匯入記號之前,可以在有效期限內擷取匯入記號的次數。 預設值是 1。

    成功的 POST api/v2/import_token 要求會建立服務實例的匯入記號。 回應內文包含與匯入記號相關聯的 meta 資料,例如建立日期及原則詳細資料。 下列 Snippet 顯示輸出範例。

    {
      "creationDate": "2019-04-08T16:58:29Z",
      "expirationDate": "2019-04-08T17:18:29Z",
      "maxAllowedRetrievals": 1,
      "remainingRetrievals": 1
    }
    

使用 CLI 建立匯入記號

請完成下列步驟,以使用 Key Protect CLI (整合在 Hyper Protect Crypto Services中) 來建立匯入記號:

  1. 設定 Key Protect CLI

  2. 使用下列指令建立匯入記號:

    ibmcloud kp import-token create
    

    您可以在 Key Protect CLI 參考資料 中找到此指令的其他參數。

使用 API 擷取匯入記號

對下列端點發出 GET 呼叫,以擷取與 Hyper Protect Crypto Services 服務實例相關聯的匯入記號。

https://<instance_ID>.api.<region>.hs-crypto.appdomain.cloud/api/v2/import_token
  1. 擷取服務及鑑別認證以在服務中使用金鑰

  2. 呼叫 金鑰管理服務 API,以擷取與服務實例相關聯的匯入記號。

    curl -X GET \
      https://<instance_ID>.api.<region>.hs-crypto.appdomain.cloud/api/v2/import_token \
      -H 'authorization: Bearer <IAM_token>' \
      -H 'bluemix-instance: <instance_ID>' \
    

    根據下表取代範例要求中的變數。

    表 1. 說明使用金鑰管理服務 API 擷取匯入記號所需的變數
    變數 說明
    區域 必要。 代表 Hyper Protect Crypto Services 服務實例所在地理區域的地區縮寫,例如 us-southau-syd。 如需相關資訊,請參閱地區服務端點
    連接埠 必要。 API 端點的埠號。
    IAM_token 必要。 您的 IBM Cloud 存取記號。 請在 cURL 要求中包含 IAM 記號的完整內容,包括 Bearer 值。 如需相關資訊,請參閱 擷取存取記號
    instance_id 必要。 指派給您 Hyper Protect Crypto Services 服務實例的唯一 ID。 如需相關資訊,請參閱 擷取實例 ID

    成功的 GET api/v2/import_token 要求會擷取服務實例的匯入記號。 回應內文包含與匯入記號相關聯的 meta 資料,例如建立日期及原則詳細資料。 下列 Snippet 顯示含有截斷值的範例輸出。

    {
      "creationDate": "2019-04-08T16:58:29Z",
      "expirationDate": "2019-04-08T17:18:29Z",
      "maxAllowedRetrievals": 1,
      "remainingRetrievals": 0,
      "payload": "MIICIjANBgkqhkiG...",
      "nonce": "8zJE9pKVdXVe/nLb"
    }
    

    回應內文也包含公開加密金鑰,您可以在將金鑰資料上傳至 Hyper Protect Crypto Services 服務實例之前,使用該金鑰來 加密根金鑰

    在此範例中,payload 值代表與匯入記號相關聯的公開金鑰。 此值已編碼 base64。 為了額外安全,Hyper Protect Crypto Services 也會提供 nonce 值,用來驗證服務的金鑰匯入要求的原始性。 若要進一步瞭解如何使用這些值,請參閱 指導教學: 建立及匯入加密金鑰

使用 CLI 擷取匯入記號

請完成下列步驟,以使用 Key Protect CLI (整合在 Hyper Protect Crypto Services中) 來擷取匯入記號:

  1. 設定 Key Protect CLI

  2. 使用下列指令擷取匯入記號:

    ibmcloud kp import-token show
    

    您可以在 Key Protect CLI 參考資料 中找到此指令的其他參數。

下一步