1.0.5 • Published 6 years ago
ethereum-rsa v1.0.5
ethereum-rsa
Encrypt and Decrypt message using Ethereum keys.
How it works?
- Let's say,
Alicewants to send secured message toBob. This is How it will work:
Aliceencrypt message using his privatekey and Bob's publickey.Alicesends encrypted message toBob.Bobdecrypt message using his privatekey and Alice publickey.
Benifits:
- Only
Bobcan read the message Bobcan be sure that the message really comes fromAlice
Installation
npm install ethereum-rsa --saveInitialization
const EthRSA = require('ethereum-rsa');Retrive PublicKey from PrivateKey:
This function will return the uncompressed publicKey from privateKey.
let publicKey = EthRSA.publicKeyByPrivateKey("4a2e11580d318f86079775229a377194d3629bb8448dfbfb8352d0cc4fc3f008");
console.log(publicKey);Output:
04de9432ee891cbc70ff41acbcb253d06317703e943de2f2cb7aaae71dfa91ba0d8c4ed05dc7a6b804134b9225a539699bedb222e73900ebeea3bbf4161045f007Encryption of Message:
Encrypt the message using sender's private key and recipient public key.
Parameters:
- message: Message in plain text.
- senderPrivateKey: Private key of the sender.
- recipientPublicKey: Public key of the recipient. Public key should be in uncompressed format & 04 attached at left.
API:
EthRSA.encryptMessage(message, senderPrivateKey, recipientPublicKey);Example:
EthRSA.encryptMessage(
"Hey There!",
"4a2e11580d318f86079775229a377194d3629bb8448dfbfb8352d0cc4fc3f008",
"044f93e10b7a052260c4686dbfca7ac09d5d830c01bfe544b92438f65ebf961d64acf9992fd70565920f303bca209f7a4a96f10510a2ed0922485b4758cc2b180a"
)
.then(console.log);Output:
br+Tol1WJkejU+rvUCm7dGm2IeOLF/SiMOi3i3Ho3G4=Decryption of Message:
Decrypt the message using sender's public key and recipient private key. Here public key should be in uncompressed format & with 04 attached left side.
Parameters:
- cipherText: Encrypted message.
- recipientPrivateKey: Private key of the recipient.
- senderPublicKey: Public key of the sender. Public key should be in uncompressed format & 04 attached at left.
API:
EthRSA.decryptMessage(cipherText, recipientPrivateKey, senderPublicKey);Example:
EthRSA.decryptMessage(
"br+Tol1WJkejU+rvUCm7dGm2IeOLF/SiMOi3i3Ho3G4=",
"e4a2d1f1568c1eb7ffacdbaea7607d9e768fd3d3d97ec5119ccf5d8bb6c0e613",
"04de9432ee891cbc70ff41acbcb253d06317703e943de2f2cb7aaae71dfa91ba0d8c4ed05dc7a6b804134b9225a539699bedb222e73900ebeea3bbf4161045f007"
)
.then(console.log);Output:
Hey There!Running tests:
npm testContributing
- Issues & Pull requests are welcome! Fork, branch, and submit PR.