Use the Pico HSM PKCS#11 interface to generate RSA or ECC keypairs. The examples below show how to create, inspect, and delete keys.
Keypair Generation
Pico HSM can generate RSA keypairs internally. It stores both keys encrypted with the MKEK, a 256-bit AES key protected inside the device. The private key stays on the device. You can export it with the wrap command, which encrypts it with a passphrase and the MKEK.
To generate a 2048-bit RSA key, run this command with pkcs11-tool:
$ pkcs11-tool -l --pin 648219 --keypairgen --key-type rsa:2048 --id 1 --label "RSA2K"
Using slot 0 with a present token (0x0)
Key pair generated:
Private Key Object; RSA
label: RSA2K
ID: 1
Usage: decrypt, sign
Access: none
Public Key Object; RSA 2048 bits
label: RSA2K
ID: 1
Usage: encrypt, verify
Access: none
ID is a hexadecimal value used to identify the key, and label is a text name. Pico HSM allows duplicate IDs or labels, but assigns each key a unique internal reference. Avoid reusing IDs or labels to prevent confusion, and use the --id parameter so you can refer to the key later.
Pico HSM accepts RSA of 1024 (rsa:1024), 2048 (rsa:2048) and 4096 bits (rsa:4096).
Caution: RSA-2048 generation may take over 20 seconds; RSA-4096 may take over 20 minutes. Neither the host nor the HSM blocks, but Pico HSM cannot accept commands while it generates the key. You can generate a key on the host and import it instead, but that does not use Pico HSM’s True RNG or HRNG. Use this method only if you have an external TRNG or do not need the highest entropy.
Pico HSM also accepts ECDSA keypairs:
- secp192r1 (prime192v1)
- secp256r1 (prime256v1)
- secp384r1 (prime384v1)
- secp521r1 (prime521v1)
- brainpoolP256r1
- brainpoolP384r1
- brainpoolP512r1
- secp192k1
- secp256k1
For an ECC key, use the command above with --key-type and one of these values: EC:secp192r1, EC:secp256r1, EC:secp384r1, EC:secp521r1, EC:brainpoolP256r1, EC:brainpoolP384r1, EC:brainpoolP512r1, EC:secp192k1, or EC:secp256r1.
Deleting existing keys
To delete the key you just generated:
pkcs11-tool -l --pin 648219 --delete-object --type privkey --id 1
