I am trying to use softhsm for my project using java 1.8-64bit.
I am trying with m first sample java class given here Connecting to SoftHSM java code
I was able to install softhsm softhsm2-windows installer.
And Also able to create token usng softhsm-util.exe tool.
but when I try to run the java code I am getting
Exception in thread "main" java.security.ProviderException: Initialization failed
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:376)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:103)
at SoftHSM.main(SoftHSM.java:44)
Caused by: java.io.IOException: The specified module could not be found.
Z:/SOFTHSM_INSTALL/lib/softhsm2-x64.dll
at sun.security.pkcs11.wrapper.PKCS11.connect(Native Method)
at sun.security.pkcs11.wrapper.PKCS11.<init>(PKCS11.java:138)
at sun.security.pkcs11.wrapper.PKCS11.getInstance(PKCS11.java:151)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:313)
... 2 more
Even though the file is available in right location as mentioned in exception.
Please help to solve this issue.
Updated System Visual C++ installed:
TLDR : If you want to use softhsm2-x64.dll
from your JAVA application then you need to install 64-bit version of Visual C++ Redistributable for Visual Studio 2015.
Detailed answer : You did install SoftHSM using SoftHSM2 installer for MS Windows.
All executables and libraries present in that package (including softhsm2-util.exe
) are 32-bit expect for softhsm2-x64.dll
which is 64-bit.
All executables and libraries present in that package (including softhsm2-util.exe
) depend on 32-bit version of Visual C++ Redistributable for Visual Studio 2015 expect for softhsm2-x64.dll
which depends on 64-bit version of Visual C++ Redistributable for Visual Studio 2015.
README.md on project website says:
These packages include both 32-bit and 64-bit versions of PKCS#11 library and require both 32-bit and 64-bit version of Visual C++ Redistributable for Visual Studio 2015 to be installed on the target system.
README.txt displayed after the installation says:
This package includes both 32-bit and 64-bit build of SoftHSM 2.2.0 statically linked to OpenSSL 1.1.0d. It requires both 32-bit and 64-bit version of Visual C++ Redistributable for Visual Studio 2015 to be installed on the target system. These can be downloaded from:
http://www.microsoft.com/en-us/download/details.aspx?id=48145
My advice: install both 32-bit and 64-bit version of Visual C++ Redistributable for Visual Studio 2015.