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