問題描述
我已經設法使用 Sun 的 MSCAPI提供者 在我的應用程序中.我現在遇到的問題是它總是彈出一個窗口,要求輸入密碼,即使我已經在代碼中提供了密碼.這是個問題,因為我需要 web 服務中的加密功能.
I've managed to use Sun's MSCAPI provider in my application. The problem I'm having now is that it always pops up a window, asking for a password, even though I've provided it in the code. This is a problem, because I need the cryptography functionality in a webservice.
這是我現在擁有的代碼:
Here's the code I have now:
String alias = "Alias to my PK";
char[] pass = "MyPassword".toCharArray();
KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null, pass);
Provider p = ks.getProvider();
Signature sig = Signature.getInstance("SHA1withRSA",p);
PrivateKey key = (PrivateKey) ks.getKey(alias, pass)
sig.initSign(key);
sig.update("Testing".getBytes());
sig.sign();
這很好用,但是當最后一行運行時,我會彈出一個詢問密碼的窗口.我該如何預防?
This is working great, but I get a popup asking for the password when the last line is run. How do I prevent that?
推薦答案
MSCAPI提供者不支持向CAPI提供密碼:
The MSCAPI provider does not support providing the password to CAPI:
假定必須提供密碼的應用程序支持兼容模式.它允許(但忽略)非空密碼.該模式默認啟用.(1)
A compatibility mode is supported for applications that assume a password must be supplied. It permits (but ignores) a non-null password. The mode is enabled by default. (1)
要通過CAPI設置密碼,必須調用CryptSetKeyParam 使用未記錄的 KP_KEYEXCHANGE_PIN 或 KP_SIGNATURE_PIN 并希望您的底層硬件令牌提供商支持它.(它們并非完全沒有文檔 - Windows CE 和 Windows Mobile 的文檔提到了它們 (2) 并且它們包含在頭文件中).
To set the password through CAPI, you must call CryptSetKeyParam with the undocumented KP_KEYEXCHANGE_PIN or KP_SIGNATURE_PIN and hope your underlying hardware token provider supports it. (They are not completely undocumented - the documentation for Windows CE and Windows Mobile mention them (2) and they are included in the header files).
這篇關于Java 安全 - MSCAPI 提供程序:如何在不彈出密碼的情況下使用?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!