我正在尝试使用 Itext 5 和 BouncyCastle 1.48 验证 PDF 签名。我的代码适用于许多签名的 pdf,但适用于特定客户的某些 pdf。这是我的Java代码
// The entry point
public static void verifySignatures(String path) throws IOException, GeneralSecurityException {
System.out.println(path);
PdfReader reader = new PdfReader(path);
AcroFields fields = reader.getAcroFields();
ArrayList<String> names = fields.getSignatureNames();
System.out.println("Il y a "+names.size()+" signatures");
for (String name : names) {
System.out.println("===== " + name + " =====");
verifySignature(fields, name);
}
System.out.println();
}
public static PdfPKCS7 verifySignature(AcroFields fields, String name)
throws GeneralSecurityException, IOException {
System.out.println("Signature covers whole document: "+ fields.signatureCoversWholeDocument(name));
System.out.println("Document revision: " + fields.getRevision(name)
+ " of " + fields.getTotalRevisions());
PdfPKCS7 pkcs7 = fields.verifySignature(name);
System.out.println("Integrity check OK? " + pkcs7.verify());
return pkcs7;
}
有时我会得到这个异常:
java.lang.IllegalArgumentException:getInstance 中的未知对象:org.bouncycastle.asn1.ASN1Sequence.getInstance(Unknown Source) at org.bouncycastle.asn1.ocsp.ResponseData.getInstance(Unknown Source) at org.bouncycastle.asn1.ASN1Enumerated .bouncycastle.asn1.ocsp.BasicOCSPResponse.(Unknown Source) at org.bouncycastle.asn1.ocsp.BasicOCSPResponse.getInstance(Unknown Source) at 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)
有没有人必须解决这个问题?