2012-10-26 21 views
0

我正在開發(java)一個需要連接到Windows密鑰庫的xml驗證應用程序。 目前我被困在以下消息:CannotBuildCertificationPathExecption:信任錨Keystore未初始化。使用XAdES4j如何將錨定信任到Windows密鑰庫?

現在我可以使用這個例子從商店得到我的密鑰:http://stackoverflow.com/questions/5476974/java-access-to-intermediate-cas-from-windows-keystores哪些工作很好。並給了我希望使用XAdES4J。

我正在使用的代碼如下:

trustAnchors = KeyStore.getInstance("Windows-MY"); 
certValidator = new PKIXCertificateValidationProvider(trustAnchors, false); 
p = new XadesVerificationProfile(certValidator); 
v = p.newVerifier(); 

Element sigElem = (Element) signature.item(0); //Which contains the complete signature segment from the xml 

XAdESVerificationResult r; 
SignatureSpecificVerificationOptions options = new SignatureSpecificVerificationOptions().useBaseUri("http://www.ietf.org/rfc/"); 

r = v.verify(sigElem, options); 

的證書是X509。加密方法XAdES-t。

有誰知道如何獲得與Windows密鑰庫的可信連接? 有沒有關於SignatureSpecificVerificationOptions的任何信息。我覺得真的很難理解上下文中的手動與實際設置我需要使用..

回答

0

即使它是一個密鑰庫的Wndows你仍然需要加載它:

trustAnchors.load(null); 

PKIXCertificateValidationProvider不能這樣做,因爲可能需要保護參數。

此外,您可能需要使用「Windows-ROOT」而不是「Windows-MY」才能訪問受信任的證書頒發機構。

+0

嗨伊根,你的回覆幫了很多。 – user1389486

相關問題