To install the modules, run:
npm install vascomm-rsa-sha
To perform the following actions, you must have OpenSSL installed on your operating system.
-
Move to the directiories where you want to generate the RSA KeyPair.
-
Generating the Private Key
openssl genrsa -out privateKey.pem 2048
Notes: you can change
privateKey.pem
to the desired output name of generated Private Key. -
Generating the Public Key
openssl rsa -pubout -in privateKey.pem -out publicKey.pem
Notes:
privateKey.pem
must be the Private Key filename. You can changepublicKey.pem
to the desired output name of generated Public Key.
let RSA_SHA = require('RSA-SHA');
let fs = require('fs');
let publicKey = fs.readFileSync('/path/to/public/key');
let privateKey = fs.readFileSync('/path/to/private/key');
let text = "Lorem Ipsum"
// Encrypt RSA
let encypted = RSA_SHA.encryptRSA(text, publicKey);
console.log(encypted)
// Decrypt RSA
console.log(RSA_SHA.decryptRSA(encypted, privateKey));
// Sign SHA
let signed = RSA_SHA.signSHA(text, privateKey);
console.log(signed);
//Verify SHA
console.log(RSA_SHA.verifySHA(text,signed, publicKey)); //true
This modules is licensed under PT Vascomm Solusi Teknologi.
- Gaby
Ask your developer related questions to Vascomm Backend Division