导入密钥 - 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