vbuch / node-signpdf

Simple signing of PDFs in node.
MIT License
719 stars 178 forks source link

TypeError: signer.sign is not a function #105

Closed GuasaPlay closed 3 years ago

GuasaPlay commented 4 years ago

Hi everyone, I am trying to implement this package following the example here, but I really don't know how to do it. I am a newbie in this topic, please help me how could I do it. This is my code:

const fs = require("fs");
const signer = require("node-signpdf");

const pdfBuffer = fs.readFileSync("./firmas/ejemplo.pdf");
const p12Buffer = fs.readFileSync("./firmas/carmen_raquel_barreto_arias.p12");

const password = "*******";

let resp = signer.sign(pdfBuffer, p12Buffer, {
  passphrase: password,
});

console.log(resp);

And this is the error it shows me:

TypeError: signer.sign is not a function
    at Object.<anonymous> (C:\Users\oscar\Desktop\PROYECTOS\sign-prueba\index.js:9:19)
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
    at Module.load (internal/modules/cjs/loader.js:879:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47

@NoahCardoza, maybe you can help me with this?

NoahCardoza commented 4 years ago

Take a look at this file. The issue is that they are using ES6 import/exports which end up exporting everything into the .default property.

To correctly import/use the module try:

const signer = require('node-signpdf').default;

signer.sign(...)
GuasaPlay commented 4 years ago

@NoahCardoza thanks it already worked. But now when I go to check if the PDF is signed it shows me that:

The signature is NOT VALID

And then if I go to the details of the signature it shows me the following: The signature was created with Not available Hash algorithm: SHA256 Signature algorithm: rsaEnvryption-pcks1.

By the way, this signature is issued by the government of my country and I suppose it is valid

Maybe you know something about this?

NoahCardoza commented 4 years ago

Interesting... Try generating your own psk12 store and see if that works?

vbuch commented 4 years ago

https://www.adobe.com/devnet-docs/etk_deprecated/tools/QuickKeys/Acrobat_SignatureValidationKey.pdf

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had activity in the past 90 days. It will be closed if no further activity occurs. Thank you for your contributions.