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.
- 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.
You can install the @pyxlab/cms_sign
package using npm:
npm install @pyxlab/cms_sign
Or using yarn:
yarn add @pyxlab/cms_sign
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);
}
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.');
}
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.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
To understand how to submit an issue, commit and create pull requests, check our Contribution Guidelines.
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.
Distributed under the ISC License. See LICENSE for more information.