signature-sdk-js
v1.0.1
Published
A JavaScript package for creating digital signatures using RSA encryption and PEM encoding.
Downloads
47
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-js
yarn add signature-sdk-js
Usage
To use signature-sdk-js
, follow these steps:
- Import the package:
import { createSignature } from "signature-sdk-js";
- Call the
createSignature
function 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 validDate
object 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);
}