-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cfeeda
commit 32af05e
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |