匯入金鑰 - AWS CloudHSM

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

匯入金鑰

若要將私密金鑰 (即:對稱金鑰和非對稱私有金鑰) 匯入 HSM,您必須先在 HSM 上建立包裝金鑰。您可以直接匯入公有金鑰,而不需包裝金鑰。

匯入私密金鑰

完成以下步驟,以匯入私密金鑰。匯入私密金鑰之前,請先儲存為檔案。將對稱金鑰儲存為原始位元組,將非對稱私有金鑰儲存為 PEM 格式。

此範例示範如何將檔案中的純文字私密金鑰匯入 HSM。若要將加密金鑰從檔案匯入 HSM,請使用指unWrapKey令。

匯入私密金鑰
  1. 使用指genSymKey令建立環繞索引鍵。以下命令會建立僅對目前工作階段而言有效的 128 位元 AES 包裝金鑰。您可以使用工作階段金鑰或持久性金鑰做為包裝金鑰。

    Command: genSymKey -t 31 -s 16 -sess -l import-wrapping-key Cfm3GenerateSymmetricKey returned: 0x00 : HSM Return: SUCCESS Symmetric Key Created. Key Handle: 524299 Cluster Error Status Node id 2 and err state 0x00000000 : HSM Return: SUCCESS
  2. 依據您要匯入的私密金鑰類型而定,使用以下其中一個命令。

    • 若要匯入對稱金鑰,請使用指imSymKey令。以下命令使用上個步驟中建立的包裝金鑰,從名為 aes256.key 的檔案匯入 AES 金鑰。若要查看所有可用的選項,請使用 imSymKey -h 命令。

      Command: imSymKey -f aes256.key -t 31 -l aes256-imported -w 524299 Cfm3WrapHostKey returned: 0x00 : HSM Return: SUCCESS Cfm3CreateUnwrapTemplate returned: 0x00 : HSM Return: SUCCESS Cfm3UnWrapKey returned: 0x00 : HSM Return: SUCCESS Symmetric Key Unwrapped. Key Handle: 524300 Cluster Error Status Node id 0 and err state 0x00000000 : HSM Return: SUCCESS Node id 1 and err state 0x00000000 : HSM Return: SUCCESS Node id 2 and err state 0x00000000 : HSM Return: SUCCESS
    • 若要匯入非對稱私密金鑰,請使用importPrivateKey指令。以下命令使用上個步驟中建立的包裝金鑰,從名為 rsa2048.key 的檔案匯入私有金鑰。若要查看所有可用的選項,請使用 importPrivateKey -h 命令。

      Command: importPrivateKey -f rsa2048.key -l rsa2048-imported -w 524299 BER encoded key length is 1216 Cfm3WrapHostKey returned: 0x00 : HSM Return: SUCCESS Cfm3CreateUnwrapTemplate returned: 0x00 : HSM Return: SUCCESS Cfm3UnWrapKey returned: 0x00 : HSM Return: SUCCESS Private Key Unwrapped. Key Handle: 524301 Cluster Error Status Node id 0 and err state 0x00000000 : HSM Return: SUCCESS Node id 1 and err state 0x00000000 : HSM Return: SUCCESS Node id 2 and err state 0x00000000 : HSM Return: SUCCESS

匯入公有金鑰

使用importPubKey指令匯入公開金鑰。若要查看所有可用的選項,請使用 importPubKey -h 命令。

以下範例會從名為 rsa2048.pub 的檔案匯入 RSA 公有金鑰。

Command: importPubKey -f rsa2048.pub -l rsa2048-public-imported Cfm3CreatePublicKey returned: 0x00 : HSM Return: SUCCESS Public Key Handle: 524302 Cluster Error Status Node id 0 and err state 0x00000000 : HSM Return: SUCCESS Node id 1 and err state 0x00000000 : HSM Return: SUCCESS Node id 2 and err state 0x00000000 : HSM Return: SUCCESS