I have a signed PDF document. It was signed by using TCPDF. Now I want to verify it. This is my solution:
- Get content of signed pdf.
- Get original content and signature value base on /ByRange field.
- Get encrypted digest message from signature value. It's octet string at the end of signature value.
- Use Openssl_public_decrypt() function to decrypt the encrypted digest message with public key. Then we have a string which has a prefix ("3021300906052b0e03021a05000414"). This prefix denotes the hash function used is SHA-1. After removing the prefix, we obtain digest message D1.
- Use SHA1() function to hash original content, we obtain digest message D2.
- Compare D1 with D2. If D1 = D2 then signature is valid and vice versa.
My problem is in last step, when I compare D1 with D2, they are not equal. I don't know why. Thanks for any help.