我正在尝试使用下一个代码来运行一个如何使用pkcs11的示例
import java.lang.reflect.Constructor;
import java.security.KeyStore;
import java.security.Provider;
import java.security.Security;
import java.util.Enumeration;
public class SignWithPKCS11
{
public static void main (String [] args)
{
try
{
Class<?> pkcs11Class = Class.forName("sun.security.pkcs11.SunPKCS11");
Constructor<?> construct = pkcs11Class.getConstructor(new Class[] {String.class});
String configName = "pkcs11.cfg";
Provider p = (Provider)construct.newInstance(new Object[] {configName});
Security.addProvider(p);
}
catch (Throwable t)
{
t.printStackTrace();
}
}
}
上面的代码调用文件pkcs11.cfg。内容是
name = JSignPdf
library = /home/grados-sanchez/grive/E-CONNECTING/david/opensc-pkcs11.so
使用此命令
java -cp . SignWithPKCS11
java -Djava.library.path=".:/home/grados-sanchez/grive/E-CONNECTING/david" -cp . SignWithPKCS11
但我明白了
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at SignWithPKCS11.main(SignWithPKCS11.java:32)
Caused by: java.security.ProviderException: Initialization failed
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:376)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:103)
Caused by: java.io.IOException: libopensc.so.6: cannot open shared object file: No such file or directory/home/grados-sanchez/grive/E-CONNECTING/david/opensc-pkcs11.so
能帮我解决一下吗?怎么了?
注意:我做的时候:
ls -l /home/grados-sanchez/grive/E-CONNECTING/david/opensc-pkcs11.so
我知道
-rw-rw-r-- 1 user user 220232 Jun 19 01:59 /home/grados-sanchez/grive/E-CONNECTING/david/opensc-pkcs11.so
答案 0 :(得分:0)
似乎丢失的不是 TypeName: System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
bsw NoteProperty System.Double bsw=3.14
name NoteProperty string name=chris
token NoteProperty string token=silver
volume NoteProperty System.Double volume=17.22
silver
,而是该库的依赖项。使用opensc-pkcs11.so
检查那些依赖关系。如果它们与提供程序位于同一目录中,则需要在执行命令之前设置ldd
(例如,作为前缀)。