is it possible to get the private key of ethereum wallet using web3js?
I want to encrypt data using the ethererum keys?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.Sign up to join this community
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; let datadir = process.argv; let pw_file = process.argv; 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