Import key material into an HSM
Import your own symmetric or asymmetric key material into a hardware security module (HSM). The procedure differs by key material type, and importing a private key additionally requires a wrapping key.
Before you begin
Applicable HSM types
You can import your own key material into the following HSM types:
General-purpose HSM (FIPS)
Prerequisites
Start the HSM client agent (hsm_proxy). For more information, see Step 2: Start the HSM client (hsm_proxy).
Tools
Before performing any operations, log in as a crypto user (CU):
$/opt/hsm/bin/key_mgmt_tool
Command: loginHSM -u CU -s <yourCuUserName> -p <yourCuUserPassword>Replace /opt/hsm/bin/key_mgmt_tool with the actual path, and replace <yourCuUserName> and <yourCuUserPassword> with your CU credentials.
Every genSymKey, imSymKey, importPrivateKey, and importPubKey command in this topic runs inside this command-line tool. The OpenSSL commands run in your shell.
Import symmetric key material
The following procedure imports AES-256 symmetric key material into an HSM. Symmetric key material is imported under a wrapping key, so the procedure has three steps: prepare the key material, generate the wrapping key, and import the key material.
Prepare the symmetric key material.
NoteIf you already have the key material, skip this step. The file must contain only the key material and no extra content, such as a line feed.
In this example, OpenSSL generates 32 bytes (256 bits) of key material for an AES-256 key:
openssl rand 32 >aes256key_to_import.keyGenerate a wrapping key.
In this example, the
-sessoption generates a temporary session key as the wrapping key.genSymKey -t 31 -s 32 -sess -l import-wrapping-keyThe following table describes the
genSymKeyparameters.Parameter Description -tThe key type. Valid values: 21 (3DES) and 31 (AES). -sThe key length, in bytes. For an AES key, valid values are 16, 24, or 32. For a 3DES key, the value must be 24. -sessCreates a temporary session key that is not persistently stored. -lThe key label. Expected output:
Cfm3GenerateSymmetricKey returned: 0x00 : HSM Return: SUCCESS Symmetric Key Created. Key Handle: 37 Cluster Status: Node id 0 status: 0x00000000 : HSM Return: SUCCESSImport the symmetric key material.
imSymKey -f aes256key_to_import.key -t 31 -l aes256-key-imported -w 37The following table describes the
imSymKeyparameters.Parameter Description -fThe name of the key material file. -tThe key type of the key material. Valid values: 16 (GENERIC_SECRET), 21 (3DES or DES), and 31 (AES). -lThe key label. -wThe identifier of the wrapping key. This is the Key Handle value in the output of the genSymKeycommand that you run to generate the wrapping key. The HSM assigns the Key Handle value randomly, so replace it with the actual value.Expected output:
Cfm3ImportWrapKey returned: 0x00 : HSM Return: SUCCESS Cfm3CreateUnwrapTemplate2 returned: 0x00 : HSM Return: SUCCESS Cfm3ImportUnWrapKey returned: 0x00 : HSM Return: SUCCESS Symmetric Key Imported. Key Handle: 35 Cluster Status: Node id 0 status: 0x00000000 : HSM Return: SUCCESS
Import asymmetric key material
The following procedures import an ECC secp256k1 key pair into an HSM. You can import either the private key or the public key of the asymmetric key material, and the part you import determines the commands you run:
Private key — Generate a wrapping key, and then run
importPrivateKey. See Import the private key.Public key only — Run
Both paths use the key material files prepared in Prepare the asymmetric key material.importPubKey. You do not need to generate a wrapping key. See Import only the public key.
Prepare the asymmetric key material
If you already have the key material, skip this step.
In this example, OpenSSL generates ECC secp256k1 asymmetric key material:
openssl ecparam -name secp256k1 -genkey -noout -out secp256k1_key.pem
openssl ec -in secp256k1_key.pem -pubout -out secp256k1_key_pub.pemThe following samples show the structure of the generated files. The key content is redacted and is shown for illustration only. Do not copy these samples as key material.
Private key file (secp256k1_key.pem):
-----BEGIN EC PRIVATE KEY-----
MHQCAQEExxxxyuf7UmNdSxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxSxxxxxAK
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx6
NpRcHyxpilxxxHolxxxxxroWwH2obVr,Ug==
-----END EC PRIVATE KEY-----Public key file (secp256k1_key_pub.pem):
-----BEGIN PUBLIC KEY-----
MFYwEAYHKoxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxo3ZiycE
xCxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxVM, Ug==
-----END PUBLIC KEY-----Import the private key
Generate a wrapping key.
genSymKey -t 31 -s 32 -sess -l import-wrapping-keyThe following table describes the
genSymKeyparameters.Parameter Description -tThe key type. Valid values: 21 (3DES) and 31 (AES). -sThe key length, in bytes. For an AES key, valid values are 16, 24, or 32. For a 3DES key, the value must be 24. -sessCreates a temporary session key that is not persistently stored. -lThe key label. Expected output:
Cfm3GenerateSymmetricKey returned: 0x00 : HSM Return: SUCCESS Symmetric Key Created. Key Handle: 37 Cluster Status: Node id 0 status: 0x00000000 : HSM Return: SUCCESSImport the private key of the asymmetric key material.
importPrivateKey -f secp256k1_key.pem -l secp256k1_key-imported -w 37The following table describes the
importPrivateKeyparameters.Parameter Description -fThe name of the private key file. -lThe key label. -wThe identifier of the wrapping key. This is the Key Handle value in the output of the genSymKeycommand that you run to generate the wrapping key. The HSM assigns the Key Handle value randomly, so replace it with the actual value.Expected output:
BER encoded key length is 135 Cfm3ImportWrapKey returned: 0x00 : HSM Return: SUCCESS Cfm3CreateUnwrapTemplate2 returned: 0x00 : HSM Return: SUCCESS Cfm3ImportUnWrapKey: 0x00 : HSM Return: SUCCESS Private Key Imported. Key Handle: 36 Cluster Status: Node id 0 status: 0x00000000 : HSM Return: SUCCESS
Import only the public key
Importing a public key does not use a wrapping key, so run importPubKey without the -w parameter:
importPubKey -f secp256k1_key_pub.pem -l secp256k1_key_pubThe following table describes the importPubKey parameters.
| Parameter | Description |
-f | The name of the public key file. |
-l | The key label. |
Expected output:
Cfm3CreatePublicKey returned: 0x00 : HSM Return: SUCCESS