Giter VIP home page Giter VIP logo

verify-pdf's Introduction

verify-pdf

Build Status

verify pdf files in JS (supports both node.js & browser).

Verifying PDF signature

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 @ninja-labs/verify-pdf

Importing

// CommonJS require
const verifyPDF = require('@ninja-labs/verify-pdf');

// ES6 imports
import verifyPDF from '@ninja-labs/verify-pdf';

Verifying

Verify the digital signature of the pdf and extract the certificates details

Node.js

const verifyPDF = require('@ninja-labs/verify-pdf');
const signedPdfBuffer = fs.readFileSync('yourPdf');

const {
    verified,
    authenticity,
    integrity,
    expired,
    signatures
} = verifyPDF(signedPdfBuffer);

Browser

import verifyPDF from '@ninja-labs/verify-pdf';

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('@ninja-labs/verify-pdf');  // require

import { getCertificatesInfoFromPDF } from '@ninja-labs/verify-pdf';  // 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.

Dependencies

node-forge is used for working with signatures.

Credits

verify-pdf's People

Contributors

mohammedessehemy avatar tarek-essam avatar dependabot[bot] avatar felixh10r avatar letrixz avatar gribera avatar herpiko avatar dependabot-preview[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.