Verify the digital signature of the pdf
npm install pdf-signature-reader
npm i pdf-signature-reader
`
Importing
`javascript
// CommonJS require
const verifyPDF = require('pdf-signature-reader');
// ES6 imports
import verifyPDF from 'pdf-signature-reader';
`
Verifying
Verify the digital signature of the pdf and extract the certificates details
$3
`javascript
const verifyPDF = require('pdf-signature-reader');
const signedPdfBuffer = fs.readFileSync('yourPdf');
const {
verified,
authenticity,
integrity,
expired,
signatures
} = verifyPDF(signedPdfBuffer);
`
$3
`javascript
import verifyPDF from 'pdf-signature-reader';
const readFile = (e) => {
const file = e.target.files[0]
let reader = new FileReader();
reader.onload = function(e) {
const { verified } = verifyPDF(reader.result);
}
reader.readAsArrayBuffer(file);
};
`
* signedPdfBuffer: signed PDF as buffer.
* verified: The overall status of verification process.
* authenticity: Indicates if the validity of the certificate chain and the root CA (overall in case of multiple signatures).
* integrity: Indicates if the pdf has been tampered with or not (overall in case of multiple signatures).
* expired: Indicates if any of the certificates has expired.
* signatures: Array that contains the certificate details and signatureMeta (Reason, ContactInfo, Location and Name) for each signature.
Certificates
You can get the details of the certificate chain by using the following api.
`javascript
const { getCertificatesInfoFromPDF } = require('pdf-signature-reader'); // require
import { getCertificatesInfoFromPDF } from 'pdf-signature-reader'; // ES6
`
`javascript
const certs = getCertificatesInfoFromPDF(signedPdfBuffer);
``