I'm using the following:
The new funny JRE 7 64bit doesn't support Sun PKCS11 anymore (which is inside package 'sun.security.pkcs11'). And the big problem is that the end-users of the product by our company may have installed whatever version of JRE.
So I have to swap up the existing to code in 'Sun PKCS11' to 'IAIK PKCS11 Wrapper'. The wrapper by IAIK works simply this way:
(iaik-wrapper.jar)->(iaik-pkcs11-jni.dll)->(pki-token-driver.dll)
The PKI token driver dynamic link library is provided by the manufacturer of PKI USB token, it has the actual name of 'ca2-v34.dll'. The method to load this native driver is described in programmer's manual as below:
import iaik.pkcs.pkcs11.*;
...
Module pkcs11Driver;
try {
pkcs11Driver = Module.getInstance("ca2-v34.dll"); //<--exception!
pkcs11Driver.initialize(null);
//test
System.out.println(pkcs11Driver.getInfo());
}
catch (Exception ex) {
System.out.println(ex);
}
The exception is raised at the line marked in the code above, with this detail: java.io.IOException: %1 is not a valid Win32 application. ca2-v34.dll
This exception surely means the IAIK library has found the .dll file, but it is not compatible somehow. I'm being stuck at this bottleneck.
As noted by EJP in the comments right below the question, ca2-v34.dll is a 32bit dll. The sample usb token manager from the manufacturer is a 32bit-throughout software, so it can load this dll file on both Windows 32 and Windows 64.
The scenario of JRE is different: