PDF文档验证异常



当我尝试验证签名的pdf文档时,我会得到RuntimeException:

Exception in thread "main" java.lang.RuntimeException: algorithm identifier 1.2.398.3.10.1.1.1.1 in key not recognised
at org.bouncycastle.jce.provider.JDKKeyFactory.createPublicKeyFromPublicKeyInfo(Unknown Source)
at org.bouncycastle.jce.provider.X509CertificateObject.getPublicKey(Unknown Source)
at com.itextpdf.text.pdf.PdfPKCS7.<init>(PdfPKCS7.java:582)
at com.itextpdf.text.pdf.PdfPKCS7.<init>(PdfPKCS7.java:421)
at com.itextpdf.text.pdf.AcroFields.verifySignature(AcroFields.java:2307)
at Main.verifyPDF(Main.java:62)
at Main.main(Main.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

我的验证代码如下:

    public static boolean verifyPDF(String fileToVerify, KeyStore trustedStore, CRL crl) throws IOException, GeneralSecurityException {
    List<CRL> crls = null;
    if (crl != null) {
        crls = new ArrayList<CRL>(1);
        crls.add(crl);
    }
    boolean result = false;
    PdfReader checker = new PdfReader(fileToVerify);
    AcroFields af = checker.getAcroFields();
    ArrayList<String> names = af.getSignatureNames();
    for (int k = 0; k < names.size(); ++k) {
        String name = (String) names.get(k);
        System.out.println("Signature: " + name);
        com.itextpdf.text.pdf.PdfPKCS7 pk = af.verifySignature(name, "KALKAN");
        result = pk.verify();
        System.out.println("Signer certificate DN: " + pk.getSigningCertificate().getSubjectDN());
        Calendar cal = pk.getSignDate();
        X509Certificate pkc[] = (X509Certificate[]) pk.getSignCertificateChain();
        System.out.println("Document modified: " + !result);
        Object fails[] = PdfPKCS7.verifyCertificates(pkc, trustedStore, crls, cal);
        if (fails == null)
            System.out.println("Certificates verified against the KeyStore");
        else
            System.out.println("Certificate failed: " + fails[1]);
    }
    return result;
}

此字符串出现异常:

com.itextpdf.text.pdf.PdfPKCS7 pk = af.verifySignature(name, "KALKAN");

我使用修补的iText库。我不得不修补它,因为没有像ECGOST34310这样的算法,我只是添加了它。签名是按照通常的方式执行的,没有问题。请帮忙!

谢谢。

乍一看,OID 1.2.398.3.10.1.1.1.1似乎是由哈萨克斯坦当局定义的(参见本页),与父OID代表的GOST 34310-2.004有关,但尚未包含在主流BouncyCastle发行版中,参见BouncyCCastle规范。

因此,就像您已经扩展iText以便能够使用GOST 34310-2.004 签名一样

我使用修补的iText库。我不得不修补它,因为没有像ECGOST34310这样的算法,我只是添加了它

您必须扩展它(或者在这种情况下,更确切地说是iText使用的加密库BouncyCastle),才能使用GOST 34310-2.004验证签名。不过,也许其他人已经这样做了,并站出来提供帮助?

顺便说一句,如果你能尽快分享结果,那就太好了。


话虽如此,我不知道GOST在ISO 32000-1或PAdES集成PDF签名的上下文中被提及。因此,将GOST用于PDF签名可能会导致非常有限的互操作性。

最新更新