signature-sdk-js
v1.0.1
Published
A JavaScript package for creating digital signatures using RSA encryption and PEM encoding.
Readme
signature-sdk-js
A JavaScript package for creating digital signatures using RSA encryption and PEM encoding.
Installation
You can install signature-sdk-js via npm or yarn:
npm install signature-sdk-jsyarn add signature-sdk-jsUsage
To use signature-sdk-js, follow these steps:
- Import the package:
import { createSignature } from "signature-sdk-js";- Call the
createSignaturefunction with the appropriate parameters:
const data = "Your data to be signed";
const privateKeyString = "Your private key in PEM format";
const dateNow = new Date(); // Current date and time
try {
const result = createSignature(data, privateKeyString, dateNow);
console.log("Signature:", result.signature);
console.log("Timestamp:", result.timestamp);
} catch (error) {
console.error("Error:", error.message);
}Parameters:
data: A non-empty string representing the data to be signed.privateKeyString: A non-empty string containing the private key in PEM format.dateNow: A validDateobject representing the current date and time.
Returns:
An object containing the following properties:
signature: The generated signature encoded in Base64 format.timestamp: The timestamp of when the signature was created (in seconds).
Example:
const data = "Hello, world!";
const privateKeyString = "-----BEGIN PRIVATE KEY-----\nYour private key here\n-----END PRIVATE KEY-----";
const dateNow = new Date();
try {
const result = createSignature(data, privateKeyString, dateNow);
console.log("Signature:", result.signature);
console.log("Timestamp:", result.timestamp);
} catch (error) {
console.error("Error:", error.message);
}