pkcs11-tool. By the end you will have a working token, a 2048-bit RSA key pair, a signed file, and a verified signature.
These steps target Debian/Ubuntu systems. Package names and library paths may differ on other distributions.
Install prerequisites
Install SoftHSM2, OpenSC, OpenSSL, CMake, and the required development libraries:
libsofthsm2-dev provides the shared library at /usr/lib/x86_64-linux-gnu/softhsm/libsofthsm2.so, which is referenced by all pkcs11-tool commands in this guide. Verify the path after installation with dpkg -L libsofthsm2.Initialize the SoftHSM token
Create a new SoftHSM2 token with the label The command prompts for a Security Officer (SO) PIN and a User PIN. For development use Example output:
FirmwareHSM:1234 as the User PIN.After initialization, list all slots to find the slot ID assigned to your new token:Generate the RSA key pair
Create a 2048-bit RSA key pair on the token using key ID A successful run prints:
10 and label FirmwareKey:Sign data
Create a test file, hash it with SHA-256, and sign the hash with your private key:
The
RSA-PKCS mechanism signs a pre-hashed digest. The input to --input-file must be the raw binary hash, not the original file. This matches the behaviour of hsm_sign_verify.sh.Alternative: use the sign and verify script
The repository includeshsm_sign_verify.sh, which automates Steps 4 and 5 for a given file. The script uses the slot ID, PIN, and key ID defined at the top of the file:
SLOT to match your token’s slot ID, then run:
<file>.sig, exports the public key to pubkey.pem, and runs openssl pkeyutl -verify. On success it prints:
Next steps
- Build the
hls-hsmC++ library with CMake and integrate theHSMclass into your application — see hls-hsm library. - Start the
pkcs11-daemonfor persistent key vault management and post-quantum key support — see pkcs11-daemon.