2016-10-03 80 views
0

我的目標是從CAC卡讀取信息並使用pkcs11從中提取信息並在我的文檔上簽名。我找不到我的硬件正確的dll,所以我在我的機器上安裝openSC和下面的代碼中使用opensc-pkcs11.dlljava.security.KeyStoreException:未找到PKCS11

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 

幫助!

+0

我認爲這個問題是您的.dll,支票如果它是你正在引用的正確的dll文件 – mhasan

+0

爲什麼不使用KeyStore keyStore = KeyStore.getInstance(「PKCS11」,p);獲得密鑰庫,可能會幫助你接近你的問題 – mhasan

+0

@ mhasan,那也沒有用。我可以從互聯網上下載該DLL嗎?我正在使用CAC卡 – dexter

回答

0

首先創建一個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); 
+0

我注意到最近編輯這篇文章,這會大大改變你的意圖,請檢查是否你的意圖是否 – Danh