I am using code from web :

import iaik.pkcs.pkcs11.Module;
import iaik.pkcs.pkcs11.Info;

public class PKCS11Test {

public static void main(String[] args) {
    if (args.length == 1) {
        try {
            Module pkcs11Module = Module.getInstance(args[0], "C:/Temp/pkcs11wrapper.dll");
            pkcs11Module.initialize(null);
            Info info = pkcs11Module.getInfo();
            System.out.println(info);
            pkcs11Module.finalize(null);
        } catch (Throwable ex) {
            ex.printStackTrace();
        }
    } else {
        printUsage();
        System.exit(1);
    }
}

protected static void printUsage() {
    System.out.println("ModuleInfo <PKCS#11 module name>");
    System.out.println("e.g.: ModuleInfo pk2priv.dll");
}

}

with parameter: pkcs11wrapper.dll and VM param -Djava.library.path=C:/Temp.

"C:/Temp/pkcs11wrapper.dll" in code is not necessary...

What I get is :

java.io.IOException: The specified procedure could not be found.

at iaik.pkcs.pkcs11.wrapper.PKCS11Implementation.connect(Native Method)
at iaik.pkcs.pkcs11.wrapper.PKCS11Implementation.<init>(PKCS11Implementation.java:183)
at iaik.pkcs.pkcs11.wrapper.PKCS11Connector.connectToPKCS11Module(PKCS11Connector.java:92)
at iaik.pkcs.pkcs11.Module.getInstance(Module.java:223)
at PKCS11Test.main(PKCS11Test.java:11)

My JRE is 64 bit, dll is 64 bit as well (replacing it with 32 bit version gives well defined error about wrong dll version) JRE is v1.7.0.21, iaik wrapper v1.2.18. If I use 32 bit JRE and 32 bit dll, error is the same.

What could be wrong here ?

I got source code for iaikPkcs11Wrapper v1.3 and when running in DEBUG mode I get to line : PKCS11Connector.connectToPKCS11Module(String, String) line: 92
where return new PKCS11Implementation(pkcs11ModulePath, pkcs11WrapperPath); gets invoked. Although PKCS11Implementation class exists among sources, debugger does not want to jump in constructor code:

ClassNotFoundException(Throwable).<init>(String, Throwable) line: 286   
ClassNotFoundException(Exception).<init>(String, Throwable) line: not available 
ClassNotFoundException(ReflectiveOperationException).<init>(String, Throwable) line: not available  
ClassNotFoundException.<init>(String) line: not available   
URLClassLoader$1.run() line: not available  
URLClassLoader$1.run() line: not available  
AccessController.doPrivileged(PrivilegedExceptionAction<T>, AccessControlContext) line: not available [native method]   
Launcher$ExtClassLoader(URLClassLoader).findClass(String) line: not available   
Launcher$ExtClassLoader(ClassLoader).loadClass(String, boolean) line: not available 
Launcher$AppClassLoader(ClassLoader).loadClass(String, boolean) line: not available 
Launcher$AppClassLoader.loadClass(String, boolean) line: not available  
Launcher$AppClassLoader(ClassLoader).loadClass(String) line: not available  
PKCS11Connector.connectToPKCS11Module(String, String) line: 92  

These results where achieved when a project containing only IAIK sources and a test class was run.

有帮助吗?

解决方案

the exception

java.io.IOException: The specified procedure could not be found.
at iaik.pkcs.pkcs11.wrapper.PKCS11Implementation.connect(Native Method)

means in the DLL pk2priv.dll (or a DLL dynamicly liked by it), the wrapper method cannot find the expected native function to connect. What driver and Hardware are you using?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top