gpt4 book ai didi

java - Xades4j 验证 - 无法创建空 :null from a http://www. w3.org/2000/09/xmldsig#

转载 作者:行者123 更新时间:2023-12-02 05:38:57 30 4
gpt4 key购买 nike

我正在尝试编写应该使用 xades4j 库验证 XML 符号的程序。

我有这样的东西:

public static void verify() throws Exception
{
FileSystemDirectoryCertStore certStore = new FileSystemDirectoryCertStore("C:\\(...)");
KeyStore trustAnchors = KeyStore.getInstance("jks");
trustAnchors.load(null);
CertificateValidationProvider certValidator = new PKIXCertificateValidationProvider(trustAnchors, false, certStore.getStore());

XadesVerificationProfile p = new XadesVerificationProfile(certValidator);
XadesVerifier v = p.newVerifier();

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
String pathToXmlFile = "C:\\(..)\\TEST20140709_04.xml";

Document docSource = builder.parse(new FileInputStream(pathToXmlFile));
docSource.getDocumentElement();

//Element sigElem = (Element)factory.newDocumentBuilder().parse(new FileInputStream(pathToXmlFile));
Element sigElem = docSource.getDocumentElement();
SignatureSpecificVerificationOptions ssvo = new SignatureSpecificVerificationOptions();
ssvo.useBaseUri("http://www.ietf.org/rfc/");

XAdESVerificationResult r = v.verify(sigElem, ssvo);


System.out.println(r.getSignatureForm());
System.out.println(r.getSignatureAlgorithmUri());
System.out.println(r.getSignedDataObjects().size());
System.out.println(r.getQualifyingProperties().all().size());
}

我收到此异常:

Exception in thread "main" xades4j.xml.unmarshalling.UnmarshalException: Bad XML signature
at xades4j.verification.XadesVerifierImpl.verify(XadesVerifierImpl.java:123)
at bankconnect2.xades.Signer.verify(Signer.java:392)
at bankconnect2.BankConnect2.main(BankConnect2.java:591)
Caused by: org.apache.xml.security.exceptions.XMLSecurityException: **Cannot create a null:null from a http://www.w3.org/2000/09/xmldsig#:Signature element**
at org.apache.xml.security.utils.ElementProxy.guaranteeThatElementInCorrectSpace(ElementProxy.java:249)
at org.apache.xml.security.utils.ElementProxy.<init>(ElementProxy.java:97)
at org.apache.xml.security.utils.SignatureElementProxy.<init>(SignatureElementProxy.java:58)
at org.apache.xml.security.signature.XMLSignature.<init>(XMLSignature.java:341)
at org.apache.xml.security.signature.XMLSignature.<init>(XMLSignature.java:326)
at xades4j.verification.XadesVerifierImpl.verify(XadesVerifierImpl.java:120)

trustAnchors 的大小为 0 - 不应该 > 0?你能指出我哪里出错了吗?

最佳答案

我注意到两件事:

如果解码异常仍然存在,则签名 XML 上可能存在错误。

关于java - Xades4j 验证 - 无法创建空 :null from a http://www. w3.org/2000/09/xmldsig#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24685913/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com