1

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:

Visual C++ in My PC Win 10

Community
  • 1
  • 1
Slok
  • 576
  • 1
  • 12
  • 27
  • Does java have read access to that location? – always_a_rookie Mar 31 '17 at 14:14
  • Yes it has access . I tried to keep in system 32 and many other folders but not helpful – Slok Apr 01 '17 at 06:43
  • @Slok did you install both 32-bit and 64-bit version of Visual C++ Redistributable for Visual Studio 2015 on the target system? – jariq Apr 04 '17 at 14:51
  • I am just trying sample program which was mentioned above in my question. I was able to install SoftHSM and able to create slot and token inside that using cmd of windows. But wanna do same operations from Java. Not getting much help...on this topic – Slok Apr 06 '17 at 06:03
  • @Slok I see your pain but you did not answer my question :) Do you have both 32-bit and 64-bit version of [Visual C++ Redistributable for Visual Studio 2015](https://www.microsoft.com/en-us/download/details.aspx?id=48145) installed on the target system? – jariq Apr 06 '17 at 06:39
  • Sorry, I have Win 64bit Windows 10 PC . May be no 32 bit I think. – Slok Apr 06 '17 at 14:12

1 Answers1

0

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.

jariq
  • 11,681
  • 3
  • 33
  • 52
  • Will try and update you. FYI: I updated my visual c++ installed in PC above. I cannot install x86 version of Visual C++ Redistributable 2015. But I installed now 64-bit version of Visual C++ Redistributable 2015. – Slok Apr 07 '17 at 07:04
  • Atleast now isue resolved Thanks jariq :-) , but it complains about slot number. Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_SLOT_ID_INVALID – Slok Apr 07 '17 at 07:12
  • @Slok That seems to be a different issue of SunPKCS11 provider so IMO you should create new SO question or search existing questions/answers. – jariq Apr 07 '17 at 07:54
  • anyway great help. Thanks I can this from here now . Seems to be I am missing Slot creation...I will do that. – Slok Apr 07 '17 at 08:03