java.security.KeyStoreException:找不到PKCS11
我的目标是从CAC卡中读取信息,并使用java.security.KeyStoreException:找不到PKCS11,java,keystore,pkcs#11,cac,Java,Keystore,Pkcs#11,Cac,我的目标是从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.SunPK
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");
使用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
救命啊 首先创建一个
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);
然后在程序中提供配置文件路径,如下所示:
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);
我相信问题出在你的.dll上,检查它是否是你引用的正确的dll文件为什么不使用KeyStore KeyStore=KeyStore.getInstance(“PKCS11”,p);要获取密钥库,可能会帮助您接近issue@mhasan那也不行。我可以从internet下载dll吗?我正在使用CAC Card我注意到这篇文章最近的一次编辑,它极大地改变了你的意图,请检查这是否是你的意图