A JavaScript package for creating digital signatures using RSA encryption and PEM encoding.
npm install signature-sdk-jssignature-sdk-js via npm or yarn:
bash
npm install signature-sdk-js
`
`bash
yarn add signature-sdk-js
`
Usage
To use signature-sdk-js, follow these steps:
1. Import the package:
`javascript
import { createSignature } from "signature-sdk-js";
`
2. Call the createSignature function with the appropriate parameters:
`javascript
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);
}
`
$3
- 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 valid Date object representing the current date and time.
$3
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).
$3
`javascript
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);
}
``