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. Sep 14, 2018 at 13:40
  • how to do with code
    – maroodb
    Sep 14, 2018 at 13:43

1 Answer 1


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). Sep 14, 2018 at 13:48
  • isn't possible using web3js?
    – maroodb
    Sep 14, 2018 at 14:26
  • @maroodb: What difference would that make? Sep 14, 2018 at 14:53
  • I need to know all possible ways ;)
    – maroodb
    Sep 14, 2018 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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