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.