Skip to content

Instantly share code, notes, and snippets.

@hscstudio
Created March 11, 2022 09:01
Show Gist options
  • Save hscstudio/86cdf478f6b7f5cfd5470f1ba85eff35 to your computer and use it in GitHub Desktop.
Save hscstudio/86cdf478f6b7f5cfd5470f1ba85eff35 to your computer and use it in GitHub Desktop.
NodeJS Digital Signature
const signer = require('node-signpdf').default
const fs = require('fs')
const { plainAddPlaceholder } = require('node-signpdf/dist/helpers');
const pdfSignedPath = `./signed.pdf`;
const pdfBuffer = fs.readFileSync(`./source.pdf`);
const certBuffer = fs.readFileSync(`./certificate.p12`);
let inputBuffer = plainAddPlaceholder({
pdfBuffer,
reason: 'Signed Certificate.',
contactInfo: 'admin@hafid.com',
name: 'Sign App',
location: 'DKI Jakarta',
signatureLength: certBuffer.length,
});
const signedPdf = signer.sign(
inputBuffer,
certBuffer,
{ asn1StrictParsing : true },
);
fs.writeFileSync(pdfSignedPath, signedPdf);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment