[英]java.security.KeyStoreException: PKCS11 not found
My goal is to read information from a CAC card and use pkcs11
to extract information from it and sign my document. 我的目标是从CAC卡中读取信息,并使用
pkcs11
从中提取信息并签署我的文档。 I couldn't find the right dll for my hardware, so I installed openSC
on my machine and used opensc-pkcs11.dll
in the following code: 我找不到适合我的硬件的正确的dll,因此我在计算机上安装了
openSC
,并在以下代码中使用了opensc-pkcs11.dll
:
String configName = "pkcs.cnf"; //my config file that points to opensc-pkcs11.dll
String PIN = "123456";
Provider p = new sun.security.pkcs11.SunPKCS11(configName);
Security.addProvider(p);
KeyStore keyStore = KeyStore.getInstance("PKCS11");
char[] pin = PIN.toCharArray();
keyStore.load(null, pin);
But I'm getting an error at the following location 但是我在以下位置出现错误
KeyStore keyStore = KeyStore.getInstance("PKCS11");
with the Error stacktrace: 错误堆栈跟踪:
java.security.KeyStoreException: PKCS11 not found
at java.security.KeyStore.getInstance(Unknown Source)
Caused by: java.security.NoSuchAlgorithmException: no such algorithm: PKCS11 for provider SunPKCS11-FooAccelerator
at sun.security.jca.GetInstance.getService(Unknown Source)
at sun.security.jca.GetInstance.getInstance(Unknown Source)
at java.security.Security.getImpl(Unknown Source)
... 2 more
Help! 救命!
First create a config.cfg
as shown below: 首先创建一个
config.cfg
,如下所示:
name=name of your CAC card
slot=1
library=C:\Windows\System32\eps2003csp11.dll
\\This is the dll file for etoken like this when you are installing driver, a separate dll file would be generated for your CAC card.
Then provide the config file path in the program, as shown below: 然后在程序中提供配置文件路径,如下所示:
Provider p = new sun.security.pkcs11.SunPKCS11(configFilepath);
Security.addProvider(p);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.