0

我来用 XAdES4j 签署一个 XML 文件,但是在验证它时,我总是得到“未指定签名节点”。显然signatureParentnull!如何解决?

这是我的代码:

FileSystemDirectoryCertStore certStore = new FileSystemDirectoryCertStore(".");
KeyStore trustAnchors = createAndLoadJKSKeyStore(".\\myStore", "mystorepass");
CertificateValidationProvider certValidator = new PKIXCertificateValidationProvider(trustAnchors, false, certStore.getStore());

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

Document sourceDoc = Signapp.getDocument(".\\TEST.XML.FILE.xml");

Element signatureParent = (Element)sourceDoc.getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE).item(0);;
XAdESVerificationResult r = v.verify(signatureParent,null);
4

2 回答 2

0

你需要:

dbFactory.SetNamespaceAware(true);

https://docs.oracle.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#setNamespaceAware(boolean)

于 2015-02-09T19:41:30.093 回答
0

这是我的 getDocument 方法:

        File fXmlFile = new File(path);
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(fXmlFile);
        doc.getDocumentElement().normalize();
        return doc;
于 2015-02-07T08:53:53.593 回答