我使用XAdES4j签署了一个XML文件,但在验证它时,我总是得到“未指定签名节点”。显然signatureParent
是null
!如何解决?
这是我的代码:
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);
答案 0 :(得分: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;
答案 1 :(得分:0)
你需要:
dbFactory.SetNamespaceAware(true);