简体   繁体   English

java.security.KeyStoreException:找不到PKCS11

[英]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.

相关问题 Linux - java.security.KeyStoreException 中的 Watchdata 检查失败:找不到 PKCS11 - Failed for Watchdata check in Linux - java.security.KeyStoreException: PKCS11 not found keytool错误:java.security.KeyStoreException:找不到BKS - keytool error: java.security.KeyStoreException: BKS not found 由于错误,使用 Java API 创建 pkcs12 失败:java.security.KeyStoreException: TrustedCertEntry not supported - Creating pkcs12 using Java API failes due to error: java.security.KeyStoreException: TrustedCertEntry not supported 将Spring Security与JAVA 11结合使用的基于SAML的SSO失败,错误为java.security.KeyStoreException:未初始化的密钥库 - SAML based SSO using Spring Security with JAVA 11 failed with error java.security.KeyStoreException: Uninitialized keystore 找不到密钥保护算法:java.security.KeyStoreException:证书链未验证 - Key protection algorithm not found: java.security.KeyStoreException: Certificate chain is not validate Java-PKCS11和MSKeyStore - Java - PKCS11 and MSKeyStore Java Access Token PKCS11未找到提供程序 - Java Access Token PKCS11 Not found Provider PKCS11机制差异+ JAVA - PKCS11 Mechanisms difference + JAVA 在64位JAVA上支持PKCS11 - Support for PKCS11 on 64 bit JAVA 一个很好的免费库,用于java中的PKCS11 - A good free library for PKCS11 in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM