is it possible to get the private key of ethereum wallet using web3js?

I want to encrypt data using the ethererum keys?

  • Yes, if you have the password. – goodvibration Sep 14 '18 at 13:40
  • how to do with code – maroodb Sep 14 '18 at 13:43

Yes, if you have the password.

Here is a NodeJS script (call it RecoverPrivateKey.js):

let fs = require("fs");
let keythereum = require("keythereum");

let address = process.argv[2];
let datadir = process.argv[3];
let pw_file = process.argv[4];

let keyObject  = keythereum.importFromFile(address, datadir);
let privateKey = keythereum.recover(fs.readFileSync(pw_file).toString(), keyObject);
console.log("0x" + privateKey.toString("hex"));

Usage example (from command-line):

node ./RecoverPrivateKey.js 01234567-89ab-cdef-0123-456789abcdef ./ ./password.txt
  • You can retrieve the address argument from the id field inside the key-file, or from the name of the key-file (its suffix). – goodvibration Sep 14 '18 at 13:48
  • isn't possible using web3js? – maroodb Sep 14 '18 at 14:26
  • @maroodb: What difference would that make? – goodvibration Sep 14 '18 at 14:53
  • I need to know all possible ways ;) – maroodb Sep 14 '18 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.