Signature is Invalid for PDF File with iText

后端 未结 1 512
天涯浪人
天涯浪人 2021-01-24 07:14

I am using swisscom digital signature service and we have a test account. Well the service requires the hash code the pdf file . We send it with

DIGEST_VALUE=$(openssl d

相关标签:
1条回答
  • 2021-01-24 07:39

    In contrast to the regular detached signatures which sign the whole signed file, integrated signatures in PDFs sign (and can only sign) everything but the space set aside for the signature itself.

    (For more backgrounds read this answer)

    Thus, when you after preparing the PDF with a placeholder to embed the signature

    give the hash code of this pdf file and get PKCS#7 responde

    you hash too much because your hashing included the (then empty, i.e. filled with '0' characters) placeholder for the actual signature. The method GetBytesToSign instead only returns the hash over the signed byte ranges, i.e. everything but the placeholder:

    byte[] array = SHA256Managed.Create().ComputeHash(appearance.GetRangeStream());
    

    You have to either takes this value or similarly hash only everything but the placeholder for the signature.

    0 讨论(0)
提交回复
热议问题