1

我的目标是从 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

帮助!

4

1 回答 1

2

首先创建一个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.

然后在程序中提供config文件路径,如下图:

Provider p = new sun.security.pkcs11.SunPKCS11(configFilepath);
Security.addProvider(p);
于 2016-12-04T07:27:33.313 回答