我在
上收到此例外PdfPKCS7 pkcs7 = fields.verifySignature(name);
这是完整的代码
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.security.PdfPKCS7;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
public class NewClass {
public static void main(String arg[])
throws IOException, GeneralSecurityException {
String path = "C:/Akshay/output.pdf";
System.out.println(path);
PdfReader reader = new PdfReader(path);
AcroFields fields = reader.getAcroFields();
ArrayList<String> names = fields.getSignatureNames();
for (String name : names) {
System.out.println("===== " + name + " =====");
verifySignature(fields, name);
}
System.out.println();
}
public static void 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());
}
}
使用jar:
答案 0 :(得分:3)
您应添加一个类似BouncyCastle的提供程序,并添加如下例所示的调用:
首先添加提供商
Security.addProvider(new BouncyCastleProvider());
然后添加提供者以获取签名
PdfPKCS7 pkcs7 = fields.verifySignature(name,"BC");