我試圖使用TSA服務器將時間戳添加到PDF文件,但添加了時間戳後Adobe Reader說該文檔自簽名以來已被更改或損壞。向PDF添加時間戳損壞文件
測試代碼:
@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
感謝, 胡利安
看看這個示例... http://developers.itextpdf.com/examples/security/digital-signatures-white-paper/digital-signatures-chapter-5#888-c5_04_ltv.java – joelgeraci
請分享樣本時間戳pdf。 – mkl
@mkl添加了示例 – shulito