Replies: 1 comment 3 replies
-
Hi @Henribou, I haven't tried your code, but I can already tell you that your approach is doomed to fail without running it ;). Unfortunately, a PDF signature is not computed by simply hashing the entire file and computing a signature over that hash. The mathematical process of calculating the signature itself is intertwined with the actual embedding of the signature in the file: you have to first render the visual appearance of the signature, allocate a "hole" in the PDF data stream that will house the CMS container, then hash everything outside the hole, and compute your signature over that hash. The result of that gets put back in the hole to create a signed PDF. In other words, you can't fully decouple the process of putting the signature in the PDF from the actual signing process. This embedding process is a bit convoluted, and automating that is where tools like pyHanko come in. You can integrate pyHanko with external signature providers, but you have to let it handle all the PDF-level state management either way. I'll refer you to the documentation for more info on the ways in which you can onboard external signers (see in particular the parts on the interrupted signing flow and extending the |
Beta Was this translation helpful? Give feedback.
-
Hello and thank you for this project !
In my project, I want my users to be able to use their certificate from their computer easily. I use for that https://fortifyapp.com/, this part specifically https://fortifyapp.com/examples#signing.
To reproduce it, you need to install Fortify. Then, in a index.html
The file inputbase64.txt is needed : for that, choose a pdf and do the following :
Then run the server with the follinwing :
On the page http://127.0.0.1:3000/, you can now select a Certificate from your computer and sign the PDF.
You will receive the string :
Copy this complete CMS to the file : outputcms.txt
Now, that is where PyHanko is needed : I got the complete CMS, I would like to sign the PDF.
You need to call the function sign_pdf_with_external_cms with the outputcms.txt path as input.
At the end, I got 2 files : inputoriginal.pdf, which is my initial PDF sent to Fortify; signed.pdf, the signed PDF by the Certificate choosen in Fortify.
But unfortunatily, the signature is invalid because the "document has been altered or corrupted since it was signed" according to Adobe Reader.
Any help is welcome ! Thanks
Beta Was this translation helpful? Give feedback.
All reactions