我是PDF文档上数字签名的新手。我希望你能帮我。
我正在使用itext7来验证文档的完整性。我已经使用了一些Itext7方法来验证基于此链接的verifySignature-nignegrityStemantegritySteNticity()和signatureCoverswholedocument 避免使用pdf-digital-signature-vulnerabilities-itext 。但是,需要进行手动验证。例如,以下链接中显示的步骤 pdf and-digital-signatures
- 使用签名者的证书解密签名的哈希;结果是消息摘要HASH1。
- 哈希字节的PDF,不包括签名本身的字节;结果是消息Digest Hash2。
- 将hash1与hash2进行比较;如果它们不完全相同,则该文件已被篡改。
因此,问题在于,我无法获得PDF哈希(PDF Hash),不包括Itext7的签名值(步骤2)。
我已经获得了签名的字节范围哈希(我认为它与步骤1相对应),其中 impatattr
从签名获得的值。我遵循了这个问题的答案:获取the-the-digest-from-a-pcks7签名的pdf-file-with-itext 。另外,我已经具有身份验证的属性( digestValue
)。
另外,我可以生成PDF哈希,但其值与签名的字节范围哈希不同。我认为是因为我得到了哈希的签名值。
我一直在努力获得PDF哈希,不包括签名值,但没有成功。因此,我无法浏览步骤3(比较两个哈希)。
如果您能帮助我,我将非常感谢。
I'm new to digital signatures on PDF documents. I hope you can help me.
I'm using iText7 to validate the document integrity. I've used some iText7 methods to validate such as verifySignatureIntegrityAndAuthenticity() and signatureCoversWholeDocument based on this link avoiding-pdf-digital-signature-vulnerabilities-itext. However, it's required to make a manual validation. For instance, the steps showed in the following link pdf-and-digital-signatures
- Decrypt the signed hash using the signer's certificate; the result is message digest hash1.
- Hash the bytes of the PDF, excluding the bytes of the signature itself; the result is a message digest hash2.
- Compare hash1 with hash2; if they aren't identical, the document has been tampered with.
So, the problem is that I can't get the pdf hash excluding the signature value (step 2) with iText7.
I've already gotten the signed byte ranges hash (I thinks it correspond to the step 1) with the digestAttr
value obtained from the signature. I followed the answer of this question: obtaining-the-hash-digest-from-a-pcks7-signed-pdf-file-with-itext. Also, I already have the authenticated attributes (DigestValue
).
Also, I can generate the pdf hash but its value is different from signed byte ranges hash. I think is because I'm getting the hash including the signature value.
I've been trying to get the pdf hash excluding the signature value but without success. Thus, I can't go through the step 3 (compare the two hashes).
I will be very grateful if you could help me.
发布评论
评论(1)
签名字典(type=Sig)包含一个名为 ByteRange 的数组。该数组定义了两个范围,即签名对象之前使用的字节范围和签名对象之后的字节范围。
在验证时,您必须检查该范围是否不排除文档的任何其他部分,除了后来添加的签名。
The Signature dictionary (type=Sig) contains an array named ByteRange. This array defines two ranges, the range of bytes to use before the signature object and the bytes coming after the signature object.
While validating, you have to check whether this range is not excluding any other parts of the document, except later added signatures.