

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

# 使用 AWS CloudHSM KMU 匯出私密金鑰
<a name="export-secret-keys"></a>

完成下列步驟， AWS CloudHSM 使用 key\$1mgmt\$1util (KMU) 從 匯出私密金鑰。

**匯出私密金鑰**

1. 使用 [genSymKey](key_mgmt_util-genSymKey.md) 命令來建立包裝金鑰。以下命令會建立僅對目前工作階段而言有效的 128 位元 AES 包裝金鑰。

   ```
   Command: genSymKey -t 31 -s 16 -sess -l export-wrapping-key
   Cfm3GenerateSymmetricKey returned: 0x00 : HSM Return: SUCCESS
   
   Symmetric Key Created.  Key Handle: 524304
   
   Cluster Error Status
   Node id 2 and err state 0x00000000 : HSM Return: SUCCESS
   ```

1. 依據您要匯出的私密金鑰類型而定，使用以下其中一個命令。
   + 若要匯出對稱金鑰，請使用 [exSymKey](key_mgmt_util-exSymKey.md) 命令。以下命令會將 AES 金鑰匯出到名為 `aes256.key.exp` 的檔案。若要查看所有可用的選項，請使用 **exSymKey -h** 命令。

     ```
     Command: exSymKey -k 524295 -out aes256.key.exp -w 524304
     Cfm3WrapKey returned: 0x00 : HSM Return: SUCCESS
     
     Cfm3UnWrapHostKey returned: 0x00 : HSM Return: SUCCESS
     
     
     Wrapped Symmetric Key written to file "aes256.key.exp"
     ```
**注意**  
命令的輸出顯示「包裝對稱金鑰」已寫入輸出檔。不過，輸出檔案包含純文字 (而非包裝) 金鑰。若要將包裝 (加密) 金鑰匯出到檔案，請使用 [wrapKey](key_mgmt_util-wrapKey.md) 命令。
   + 若要匯出私有金鑰，請使用 **exportPrivateKey** 命令。以下命令會將私有金鑰匯出到名為 `rsa2048.key.exp` 的檔案。若要查看所有可用的選項，請使用 **exportPrivateKey -h** 命令。

     ```
     Command: exportPrivateKey -k 524296 -out rsa2048.key.exp -w 524304
     Cfm3WrapKey returned: 0x00 : HSM Return: SUCCESS
     
     Cfm3UnWrapHostKey returned: 0x00 : HSM Return: SUCCESS
     
     PEM formatted private key is written to rsa2048.key.exp
     ```