Skip to content

Instantly share code, notes, and snippets.

@anupam-io
Created April 5, 2021 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anupam-io/a639271dc252ad9dcd6022831f891c5e to your computer and use it in GitHub Desktop.
Save anupam-io/a639271dc252ad9dcd6022831f891c5e to your computer and use it in GitHub Desktop.
Encrypting & Decrypting data with web3 on ETH
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