Created
March 11, 2022 09:01
-
-
Save hscstudio/86cdf478f6b7f5cfd5470f1ba85eff35 to your computer and use it in GitHub Desktop.
NodeJS Digital Signature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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