vbuch / node-signpdf

Simple signing of PDFs in node.
MIT License
688 stars 175 forks source link

How to supply password to sign pdf document #110

Closed maielo closed 3 years ago

maielo commented 3 years ago

I am trying to sign existing PDF. Adding placeholder and added certificate which was supplied by gov. Tried .pfx, p12 certs but it still throws error

Error: PKCS#12 MAC could not be verified. Invalid password?
   forge\lib\pkcs12.js:475:13)
   at SignPdf.sign (C:\web_projects\**\node-signpdf\dist\signpdf.js:79:43)

OR

Error: Unable to decrypt PKCS#8 ShroudedKeyBag, wrong password?
    at _decodeSafeContents (C:\web_projects\**\node-forge\lib\pkcs12.js:667:17)
   at _decodeAuthenticatedSafe (C:\web_projects\**\node-forge\lib\pkcs12.js:564:20)
    at Object.p12.pkcs12FromAsn1 (C:\web_projects\**\node-forge\lib\pkcs12.js:479:3)
    at SignPdf.sign (C:\web_projects\**\node-signpdf\dist\signpdf.js:79:43)

any idea what i am doing wrong?

maielo commented 3 years ago

Found it in code. Nevermind. for those who search for it like i do. ->

sign(pdfBuffer, p12Buffer, additionalOptions = {}) {
    const options = {
      asn1StrictParsing: false,
      passphrase: '',
      ...additionalOptions
    };
vbuch commented 3 years ago

Yup. https://github.com/vbuch/node-signpdf/blob/develop/src/signpdf.test.js#L242 The main idea of the package was to have stuff shown with examples. Sorry you needed to search for it and it was not directly linked somewhere. Maybe an .md file with index of demonstrated features would be a nice thing to have. If someone wants to do that, PRs are welcome.

maielo commented 3 years ago

I can write do that once i have time. Will create PR for it.