Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Itext验证Pdf签名时出错_Java_Pdf_Itext_Digital Signature_Bouncycastle - Fatal编程技术网

Java 使用Itext验证Pdf签名时出错

Java 使用Itext验证Pdf签名时出错,java,pdf,itext,digital-signature,bouncycastle,Java,Pdf,Itext,Digital Signature,Bouncycastle,我正在尝试使用Itext 5和BouncyCastle 1.48验证PDF签名。我的代码适用于许多已签名的pdf,但也适用于特定客户的某些pdf。这是我的Java代码 //入口点 公共静态无效验证签名(字符串路径)引发IOException、GeneralSecurityException{ System.out.println(路径); PdfReader reader=新PdfReader(路径); AcroFields=reader.getAcroFields(); ArrayList n

我正在尝试使用Itext 5和BouncyCastle 1.48验证PDF签名。我的代码适用于许多已签名的pdf,但也适用于特定客户的某些pdf。这是我的Java代码

//入口点
公共静态无效验证签名(字符串路径)引发IOException、GeneralSecurityException{
System.out.println(路径);
PdfReader reader=新PdfReader(路径);
AcroFields=reader.getAcroFields();
ArrayList name=fields.getSignatureNames();
System.out.println(“Il y a”+names.size()+签名”);
for(字符串名称:名称){
System.out.println(“==”+name+“==”);
验证签名(字段、名称);
}
System.out.println();
}
公共静态PdfPKCS7验证签名(AcroFields字段,字符串名称)
抛出GeneralSecurityException,IOException{
System.out.println(“签名覆盖整个文档:+字段.签名覆盖整个文档(名称));
System.out.println(“文档修订:”+字段.getRevision(名称)
+“of”+字段。getTotalRevisions());
PdfPKCS7 pkcs7=字段。验证签名(名称);
System.out.println(“完整性检查正常?”+pkcs7.verify());
返回pkcs7;
}
有时我会遇到这样的例外:

java.lang.IllegalArgumentException:getInstance中的未知对象:org.bouncycastle.asn1.ASN1Enumerated 位于org.bouncycastle.asn1.ASN1Sequence.getInstance(未知源) 位于org.bouncycastle.asn1.ocsp.ResponseData.getInstance(未知源) 在org.bouncycastle.asn1.ocsp.basicospsresponse(未知来源) 位于org.bouncycastle.asn1.ocsp.basicospronse.getInstance(未知源) 请访问com.itextpdf.text.pdf.security.PdfPKCS7.findOcsp(PdfPKCS7.java:1284) 请访问com.itextpdf.text.pdf.security.PdfPKCS7.(PdfPKCS7.java:382) 请访问com.itextpdf.text.pdf.AcroFields.verifySignature(AcroFields.java:2317)


有人曾经解决过这个问题吗?

我设法找到了问题所在

BouncyCastle库之间存在冲突,我注意到Grails(我使用的框架)嵌入了另一个版本的BouncyCastle

我从BuildConfig.groovy中排除了thoses jar

   // inherit Grails' default dependencies
   inherits("global") {
      excludes 'bcprov-jdk15', 'bcpg-jdk15', 'bcmail-jdk15' 
   }

。。。它可以工作。

异常表示问题在于处理对OCSP检查的响应(以确保证书未被吊销-通常通过HTTP请求完成检查)。如果它特定于一个客户的证书,那么他们的证书可能指定了一个特定的OCSP响应程序(通过AuthorityInformationAccess扩展中的URI),并且该响应程序在某种程度上存在错误(或者只是在该URI上不实际可用)。请提供一个显示此行为的示例文档。好的,谢谢您的评论,我要检查这一点。