Sar*_*ara 4 java pdf hash signed itext
I have a signed PDF. The signature covers the entire documents and it's valid.
I want to extract the original pdf to compare its hash with that of the unsigned pdf.
I extract original pdf using the following code:
PdfReader reader = new PdfReader(FILESIGNED);
AcroFields acrofields = reader.getAcroFields();
//pdf have a unique signature
String signatureName = acrofields.getSignatureNames().get(0);
FileOutputStream os = new FileOutputStream(FILEORIGINAL);
InputStream ip = acrofields.extractRevision(signatureName);
int n = 0;
byte bb[] = new byte[1028];
while ((n = ip.read(bb)) > 0)
os.write(bb, 0, n);
os.close();
ip.close();
reader.close();
Run Code Online (Sandbox Code Playgroud)
But the extracted pdf is not the same as the original. I would extract revision before signature? Is it possible?
Thanks for help. Sara
我想提取原始 pdf 以将其哈希与未签名 pdf 的哈希进行比较。
一般来说这是不可能的。
当 iText(或其他 PDF 签名库或应用程序)签署 PDF 时,它们:
因此,通常无法再从签名的 PDF 文件中提取“原始 pdf”,因为上述更改可能从根本上改变了 PDF 的内部结构。
但有一个例外:如果这些更改作为增量更新应用(用 iText 行话来说:在追加模式中),通常可以通过切断该增量更新来检索原始更新。
为此,只需在签名之前搜索最新的文件结束标记,然后将其切断。(实际上存在一些不安全因素,最终的行尾标记可能是也可能不是原始 PDF 的一部分。)
归档时间: |
|
查看次数: |
2300 次 |
最近记录: |