我的目标是从CAC卡中读取信息,并使用pkcs11
从中提取信息并签署我的文档。我无法为我的硬件找到合适的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);
但我在以下位置收到错误
KeyStore keyStore = KeyStore.getInstance("PKCS11");
使用错误堆栈跟踪:
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
帮助!
答案 0 :(得分:0)
首先创建一个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.
然后在程序中提供配置文件路径,如下所示:
Provider p = new sun.security.pkcs11.SunPKCS11(configFilepath);
Security.addProvider(p);