您好,我正在尝试使用 Java 从我的智能卡访问 keystore 。我正在使用以下代码..
我正在使用 OpenSc 的 Pkcs11 实现 http://www.opensc-project.org/opensc
文件windows.cnf =
name=dnie
library=C:\WINDOWS\system32\opensc-pkcs11.dll
Java 代码 =
String configName = "windows.cnf"
String PIN = "####";
Provider p = new sun.security.pkcs11.SunPKCS11(configName);
Security.addProvider(p);
KeyStore keyStore = KeyStore.getInstance("PKCS11", "SunPKCS11-dnie"); =)(=
char[] pin = PIN.toCharArray();
keyStore.load(null, pin);
当执行通过 =)(= 时抛出以下异常
java.security.KeyStoreException: PKCS11 not found
at java.security.KeyStore.getInstance(KeyStore.java:635)
at ObtenerDatos.LeerDatos(ObtenerDatos.java:52)
at ObtenerDatos.obtenerNombre(ObtenerDatos.java:19)
at main.main(main.java:27)
Caused by: java.security.NoSuchAlgorithmException: no such algorithm: PKCS11 for provider SunPKCS11-dnie
at sun.security.jca.GetInstance.getService(GetInstance.java:70)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:190)
at java.security.Security.getImpl(Security.java:662)
at java.security.KeyStore.getInstance(KeyStore.java:632)
我认为问题是“SunPKCS11-dnie”,但我不知道放在那里。我尝试了很多组合...
任何人都可以帮助我...
最佳答案
我也收到如下错误:
引起:java.security.NoSuchAlgorithmException:没有这样的算法:PKCS11 for provider SunPKCS11
我正在通过 bat 文件从 jar 运行应用程序。
我的bat文件我替换了代码:java - jar sign.jar
使用代码:java -Djava.security.debug=sunpkcs11,pkcs11 -jar SigningUtility.jar
它解决了这个问题。
关于Java 访问 token PKCS11 未找到提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4833989/