Created
April 5, 2021 19:25
-
-
Save anupam-io/a639271dc252ad9dcd6022831f891c5e to your computer and use it in GitHub Desktop.
Encrypting & Decrypting data with web3 on ETH
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
data = ""; | |
privateKey = ""; | |
rpcEndpoint = ""; | |
password = ""; | |
const Web3 = require("web3"); | |
const provider = new Web3.providers.HttpProvider(rpcEndpoint); | |
const web3 = new Web3(provider); | |
async function main() { | |
// A signed message using your private key | |
signedMessage = await web3.eth.accounts.sign(data, privateKey); | |
console.log(signedMessage); | |
// Encrypting an account with a password | |
keystoreJsonV3 = await web3.eth.accounts.encrypt(privateKey, password); | |
console.log(keystoreJsonV3); | |
// Decrypting an account with a password | |
myAccount = web3.eth.accounts.decrypt(keystoreJsonV3, password); | |
console.log(myAccount); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment