【发布时间】:2017-08-25 20:46:20
【问题描述】:
我正在尝试使用 TSA 服务器为 PDF 文件添加时间戳,但在添加时间戳后,Adobe Reader 显示文档自签名后已被更改或损坏。
测试代码:
@SpringBootApplication
public class TestTimestampApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(TestTimestampApplication.class, args);
}
@Override
public void run(String... arg0) throws Exception {
TSAClient tsa = new TSAClientBouncyCastle("http://tsa.buenosaires.gob.ar/TSS/HttpTspServer");
try (OutputStream os = new FileOutputStream("I:/output.pdf")) {
PdfReader reader = new PdfReader("I:/input.pdf");
PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0', null, true);
PdfSignatureAppearance sap = stamper.getSignatureAppearance();
LtvTimestamp.timestamp(sap, tsa, "Atenea");
}
}
}
我正在使用这些框架来做时间戳:
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.12</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.58</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.58</version>
</dependency>
当我打开输出文件时,我得到了这个:
知道可能是什么问题吗??
输出文件示例:https://drive.google.com/file/d/0B5OSF4ESCy5gRU5xTXQxU2NEMmM/view?usp=sharing
谢谢, 朱利安
【问题讨论】:
-
请分享一个带有时间戳的 pdf 样本。
-
@mkl 添加了示例
-
@joelgeraci 如果我正确理解代码,该示例会为 PDF 文件中已存在的签名添加时间戳。我想要实现的是添加一个没有签名的时间戳(我开始怀疑它是否可能)
-
“我想要实现的是添加一个没有签名的时间戳(我开始怀疑这是可能的” - 没有规范要求这样做文档时间戳只允许在签名之后。结果只是不匹配任何基线或扩展 PAdES 配置文件,但这些配置文件无论如何都是以签名为中心的。特别是结果不应声称更改或损坏。
标签: java pdf timestamp itext bouncycastle