@unabandoned/pdf-signature-reader
v1.4.5
Published
Verify the digital signature of the pdf
Maintainers
Readme
@unabandoned/pdf-signature-reader
Verify the digital signature of a PDF.
A maintained fork of yudayahya/pdf-signature-reader, which has had no commit or release since April 2024. Published as
@unabandoned/pdf-signature-reader; the API is unchanged from upstream. Upstream vendored a copy of[email protected]into the package, where no dependency update could reach it — this fork uses the platform'sbuffermodule instead: Node's nativeBuffer, or in a browser the shim your bundler provides forbuffer. It has no runtime dependency beyondnode-forge.
The signed PDF file has the public certificate embedded in it, so all we need to verify a PDF file is the file itself.
Installation
npm i @unabandoned/pdf-signature-readerImporting
// CommonJS require
const verifyPDF = require('@unabandoned/pdf-signature-reader');
// ES6 imports
import verifyPDF from '@unabandoned/pdf-signature-reader';Verifying
Verify the digital signature of the pdf and extract the certificates details
Node.js
const verifyPDF = require('@unabandoned/pdf-signature-reader');
const signedPdfBuffer = fs.readFileSync('yourPdf');
const {
verified,
authenticity,
integrity,
expired,
signatures
} = verifyPDF(signedPdfBuffer);Browser
The package does require('buffer'). browserify and webpack 4 substitute a
browser shim automatically; with Vite or webpack 5, alias buffer to a shim
such as @unabandoned/buffer
(resolve.alias / resolve.fallback).
import verifyPDF from '@unabandoned/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.
const { getCertificatesInfoFromPDF } = require('@unabandoned/pdf-signature-reader'); // require
import { getCertificatesInfoFromPDF } from '@unabandoned/pdf-signature-reader'; // ES6
const certs = getCertificatesInfoFromPDF(signedPdfBuffer);signedPdfBuffer: signed PDF as buffer.
certs:
- issuedBy: The issuer of the certificate.
- issuedTo: The owner of the certificate.
- validityPeriod: The start and end date of the certificate.
- pemCertificate: Certificate in pem format.
- clientCertificate: true for the client certificate.
Credits
- This incredible NPM Package by ninja-labs-tech.
- yudayahya/pdf-signature-reader, the direct upstream of this fork.
