我的目标是从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帮助!
发布于 2016-12-04 15:27:33
首先创建一个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);https://stackoverflow.com/questions/39825759
复制相似问题