我正在尝试检查 PDF 文件的给定签名是否存在时间戳。到目前为止,我来到这个代码:
RandomAccessFileOrArray random =
new RandomAccessFileOrArray(new File("temp.pdf").getAbsolutePath());
PdfReader reader = new PdfReader(random, null);
AcroFields af = reader.getAcroFields();
ArrayList<?> names = af.getSignatureNames();
//this are the signatures?
for (Object o : names){
AcroFields.Item item = (Item) af.getFields().get((String)o);
//this is the class for verifying the signature,
//how do I get it from the item?
PdfPKCS7 pdfPKCS7 = null; //XYZ ???
Calendar signingDate = pdfPKCS7.getTimeStampDate();
}
我显然可以访问签名,但我应该到 PdfPKCS7 类来验证签名。有谁知道我怎么去那里?
1 回答
您应该使用
AcroFields
方法verifySignature(String name)
返回PdfPKCS7
对象以继续验证。该方法的 JavaDocs 显示了它的一个使用示例:
在这里,您可以使用
PdfPKCS7
实例轻松添加其他代码。Ceterum censeo ...除非你受到那个古老的 iText 版本的限制(e.g. 由于兼容性或许可证问题),你应该考虑更新到当前版本。