Skip to content

Commit

Permalink
added example
Browse files Browse the repository at this point in the history
  • Loading branch information
meetsiraja committed Mar 4, 2020
1 parent 4cfeeda commit 32af05e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions example/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const CONFIG = {
SENDER_PRIVATEKEY: "4a2e11580d318f86079775229a377194d3629bb8448dfbfb8352d0cc4fc3f008",
RECEIPIENT_PRIVATEKEY: "e4a2d1f1568c1eb7ffacdbaea7607d9e768fd3d3d97ec5119ccf5d8bb6c0e613"
}

module.exports = CONFIG;
32 changes: 32 additions & 0 deletions example/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const EthRSA = require('ethereum-rsa');
const CONFIG = require('./config')

// Will encrypt message and compress message in base64 encoded format
async function encrypt(message, senderPrivateKey, recipientPublicKey){
let cipherText = await EthRSA.encryptMessage(message, senderPrivateKey, recipientPublicKey);
return cipherText
}

// Will decrypted message from compressed cipher text
async function decrypt(cipherText, recipientPrivateKey, senderPublicKey){
let decryptedMessage = await EthRSA.decryptMessage(cipherText, recipientPrivateKey, senderPublicKey);
return decryptedMessage
}

async function test(){

let recipientPublicKey = EthRSA.publicKeyByPrivateKey(CONFIG.RECEIPIENT_PRIVATEKEY);

let cipherText = await encrypt("Hey There!", CONFIG.SENDER_PRIVATEKEY, recipientPublicKey);
console.log(`Encrypted Message: ${cipherText}`);

let senderPublicKey = EthRSA.publicKeyByPrivateKey(CONFIG.SENDER_PRIVATEKEY);

let decryptedMessage = await decrypt(cipherText, CONFIG.RECEIPIENT_PRIVATEKEY, senderPublicKey);
console.log(`Decrypted Message: ${decryptedMessage}`);

return;
}

test();

14 changes: 14 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "example",
"version": "1.0.0",
"description": "",
"main": "config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"ethereum-rsa": "^1.0.2"
}
}

0 comments on commit 32af05e

Please sign in to comment.