我尝试使用此方法验证签名和时间戳
private static boolean verifyXAdEST(String folder, String file) {
try {
FileSystemDirectoryCertStore store = new FileSystemDirectoryCertStore("C:/Certs");
FileInputStream fis = new FileInputStream("C:/Certs/cert.pfx");
KeyStore ks = KeyStore.getInstance("pkcs12");
ks.load(fis, "SECRET_PASS".toCharArray());
fis.close();
CertificateValidationProvider provider = new PKIXCertificateValidationProvider(ks, false, store.getStore());
XadesVerifier verifier = new XadesVerificationProfile(provider)
.newVerifier();
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.parse(new File(folder + file));
doc.getDocumentElement().normalize();
Element sig = (Element)doc.getElementsByTagName("ds:Signature").item(0);
XAdESVerificationResult result = verifier.verify(
sig, null,
new XadesFormatExtenderProfile().getFormatExtender(),
XAdESForm.T);
return true;
} catch (Exception ex) {
System.err.println("Error: " + ex.getMessage());
}
return false;
}
但该方法返回Bad XML签名。
有人可以帮助我!! 感谢