Reputation: 1571
I have a original PDF document and separate file as PKCS#7 signed data. I would like to combine these to create signed PDF document so that it could be shown in for example Adobe reader that it is signed and who signed the document.
Are there any libraries in Java that could be used to create such signed PDF document programatically? I need to load that PDF and add the signature to it somehow, then save it as a new PDF document.
Sample code would be appreciated.
EDIT:
The resulting code should take the PDF document as input parameter and do the following:
As I understand the first step is important because without that the PKCS#7 signed data would be wrong.
Upvotes: 3
Views: 4826
Reputation: 774
If I correctly understand your question, your pkcs#7 is signing the whole content of the PDF. That is, all PDF file bytes. In this case the answer is you can't.
When you sign a PDF file you don't sign all its bytes "as is". Before signing a PDF you have to create two "byte ranges" in the PDF, leaving in the midle of the PDF enough room to include the signature. Then you have to concatenate these two byte ranges, sign these bytes and include the signature in the space you left inside the PDF.
Take a look at
* https://www.adobe.com/devnet-docs/acrobatetk/tools/DigSig/Acrobat_DigitalSignatures_in_PDF.pdf (www.adobe.com)
Upvotes: 5
Reputation: 457
Try Apache PDFBox
Also, check out the following posts it goes over signing PDFs.
How to sign pdf in Java using pdfbox
Upvotes: 0