我正在开发(java)需要连接到Windows密钥库的xml验证应用程序。
目前,我停留在以下消息中:CannotBuildCertificationPathExecption:信任锚密钥库未初始化。

现在,我可以使用以下示例从商店中获取密钥: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的任何信息。我发现很难根据需要使用的实际设置来理解手册。

最佳答案

即使它是Wndows密钥库,您仍然需要加载它:

trustAnchors.load(null);


PKIXCertificateValidationProvider无法执行此操作,因为可能需要保护参数。

另外,您可能希望使用“ Windows-ROOT”而不是“ Windows-MY”来访问受信任的证书颁发机构。

07-28 13:22
查看更多