javanosuchmethoderrorpkcs#11iaik-jce

iaik pkcs#11 wrapper and java.lang.NoSuchMethodError


I am trying to run a simple sample code from iaik pkcs#11 wrapper (version 1.3, the latest atm) but get NoSuchMethodError on pkcs11Module.initialize call.

Module pkcs11Module = Module.getInstance("siecap11");
pkcs11Module.initialize(null); 
Slot[] slots = pkcs11Module.getSlotList(Module.SlotRequirement.TOKEN_PRESENT);
for (Slot s: slots) {
    System.out.println(s.getSlotID());
}
pkcs11Module.finalize(null);

Exception stack trace is as following

java.lang.NoSuchMethodError:     iaik.pkcs.pkcs11.wrapper.PKCS11.C_Initialize(Ljava/lang/Object;Z)V
at iaik.pkcs.pkcs11.Module.initialize(Module.java:308)
at test.pkcs11.Pkcs11Service.listSlotsWithTokens(Pkcs11Service.java:98)
at test.pkcs11.TestPkcs11Service.testListSlots(TestPkcs11Service.java:35)

A similar code works fine on Linux, so i am guessing there is something wrong with pkcs11wrapper.dll.

pkcs11wrapper.dll and siecap11.dll are in c\windows\system32 directory and both are 32bit modules.

I have tried a different pkcs#11 provider, debug and release versions of pkcs11wrapper but the result was the same.

The debug version of the pkcs11wrapper.dll generates the following output:

11/26/13 21:30:50   CALL: entering (in Java_iaik_pkcs_pkcs11_wrapper_PKCS11Implementation_initializeLibrary)
11/26/13 21:30:50   CALL: exiting  (in Java_iaik_pkcs_pkcs11_wrapper_PKCS11Implementation_initializeLibrary)
11/26/13 21:30:50   CALL: entering (in Java_iaik_pkcs_pkcs11_wrapper_PKCS11Implementation_connect)
11/26/13 21:30:50   INFO: connect to PKCS#11 module: siecap11 ...  (in Java_iaik_pkcs_pkcs11_wrapper_PKCS11Implementation_connect)
11/26/13 21:30:50   CALL: exiting  (in Java_iaik_pkcs_pkcs11_wrapper_PKCS11Implementation_connect)

The utility applications that came with the smart cards work fine, so is opensc pkcs11-tool.

EDIT:

Using version 1.2.17 of pkcs11 wrapper library and its accompanying dll, the code above works without a problem. But the original question remains unresolved.

EDIT2:

Following code, suggested by SubOptimal generates the following output.

@Test
public void testFindLibrary() {
    String lineSeparator = System.getProperty("path.separator");
    String libraryPath = System.getProperty("java.library.path");
    for (String dir : libraryPath.split(lineSeparator)) {
        File f = new File(dir + "/" + "pkcs11wrapper.dll"); 
        if (f.exists()) {
            System.out.println("found in: " + f.getAbsolutePath());
        }
    }
}

output:

found in: C:\Windows\system32\pkcs11wrapper.dll
found in: C:\Windows\system32\pkcs11wrapper.dll
found in: C:\Windows\system32\pkcs11wrapper.dll

Solution

  • After moving to a new computer the problem vanished. There was possibly another version of DLL somewhere in the java library / system path.