尝试验证签名和时间戳失败

时间:2017-02-16 17:09:35

标签: java xml-signature xades4j

我尝试使用此方法验证签名和时间戳

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签名。

有人可以帮助我!! 感谢

0 个答案:

没有答案