/
Importing key and certificate using pkcs11-tool and getting it from java application

Importing key and certificate using pkcs11-tool and getting it from java application



Convert the key and certificate to DER format

openssl rsa -in ./client1.key -outform DER -out clientkey.der
openssl x509 -outform DER -in ./client1.cert -out client1.der

Import the key and certificate using pkcs11-tool


pkcs11-tool --module /usr/lib/x86_64-linux-gnu/softhsm/libsofthsm2.so -l --pin 123456789 --write-object ./clientkey.der --type privkey --id 2222
pkcs11-tool --module /usr/lib/x86_64-linux-gnu/softhsm/libsofthsm2.so -l --pin 123456789 --write-object ./client1.der --type cert --id 2222

Get the key from java application

Use the id in hex format to access the key entry

PrivateKeyEntry privateKeyEntry = (PrivateKeyEntry) keyStore.getEntry("0x2222", null);

Related content