Skip to content

The @pyxlab/cms_sign project is a TypeScript library developed to facilitate the signing and verification of digital documents using the CMS (Cryptographic Message Syntax) standard. Using the node-forge library

License

Notifications You must be signed in to change notification settings

Pyxlab/cms_sign

Repository files navigation

@pyxlab/cms_sign


gh-workflow-image npm-image license-image

Introduction

The @pyxlab/cms_sign package is a robust solution for creating and managing digital signatures in your projects. With an intuitive and flexible API, this package allows for the generation of digital signatures, verification of existing signatures, and manipulation of signature-related data in a secure and efficient manner.

Features

  • Digital Signature Creation: Easily generate digital signatures for your documents and data.
  • Signature Verification: Verify the authenticity of digital signatures.
  • Compression Support: Option to compress signed data, reducing the final file size.
  • Output Customization: Set custom output paths, file names, and more.

Installation

You can install the @pyxlab/cms_sign package using npm:

npm install @pyxlab/cms_sign

Or using yarn:

yarn add @pyxlab/cms_sign

Usage

Creating a Digital Signature

To create a digital signature, you can use the SignatureBuilder class:

import { SignatureBuilder } from '@pyxlab/cms_sign';

const builder = new SignatureBuilder();

try {
    const file = await builder.setDataBuffer(/* your data Buffer here */)
       .setSignaturePath(/* path to the signature file */)
       .setPassphrase(/* your passphrase here */)
       .setOutputPath(/* output path */)
       .setFilename(/* output file name */)
       .setCompression(true); // Enables compression
       .build();
} catch (error) {
  console.error('Error creating digital signature:', error);
}

Verifying a Digital Signature

To verify a digital signature, you can use node-forge:

import fs from 'fs';
import forge from 'node-forge';

// Load the text file and signature
const txtFilePath = 'path/to/your/file.txt';
const signatureFilePath = 'path/to/your/file.txt.p7s';

const txtFileContent = fs.readFileSync(txtFilePath, 'utf8');
const signatureContent = fs.readFileSync(signatureFilePath, 'binary');

// Decode the signature
const p7 = forge.pkcs7.messageFromPem(signatureContent);

// Verify if the text file was correctly signed
const verified = p7.verify({content: txtFileContent});

if (verified) {
  console.log('The signature is valid.');
} else {
  console.log('The signature is invalid.');
}

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Contribution Guidelines

To understand how to submit an issue, commit and create pull requests, check our Contribution Guidelines.

Code of Conduct

We expect you to follow our Code of Conduct. You can read it to understand what kind of behavior will and will not be tolerated.

License

Distributed under the ISC License. See LICENSE for more information.

Built with ❤︎ by Walaff Fernandes

About

The @pyxlab/cms_sign project is a TypeScript library developed to facilitate the signing and verification of digital documents using the CMS (Cryptographic Message Syntax) standard. Using the node-forge library

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published