Validate file signature in Node.js

Viewed 1909

I have a pdf file signed in Adobe Reader with some Key Algorithm, say 1024-bit RSA. How can I validate the signature in Node.js having both signed file and Public Key?

I know there is a native module crypto. But I cannot understand how to use it, here is an example from docs:

const verify = crypto.createVerify('RSA-SHA256');
verify.write('some data to sign'); // should I write pdf file byte stream here?
verify.end();

const publicKey = getPublicKeySomehow();
const signature = getSignatureToVerify(); // this is not clear, what is the signature in current context?
console.log(verify.verify(publicKey, signature));

Can anyone please shed some light on this?

UPD from what I found here is the proper way to use it:

const res = verify.verify(fs.readFileSync('cert.cer'), fs.readFileSync('signed_doc.pdf'))

but it throws the next error

Error: PEM_read_bio_PUBKEY failed
    at Error (native)
    at Verify.verify (crypto.js:311:23)

Question: can I use Verify.verify with p7c, cer certificates?

0 Answers
Related