[Ethereum] Recovering private key from keystore file

etherkeystorepasswordprivate-key

Recently I came across my old keystore file from the original Ethereum Wallet that I used back in 2017. Unfortunately I cannot find the private key or password for that wallet anymore, big problem of not writing it down on a piece of paper and save that…
The issue is that I am hoping to recover the private key from my keystore file with coding or another way. I have been trying to look it up but couldn't find something useful so far.
Is there anyone who knows a way to recover the private key from your keystore file without the password?

Best Answer

Private key recovery instructions:

  1. Download and install NodeJS
  2. Create a new folder, and:
    • Copy your key-store file into this folder
    • Create a new file called run.js in this folder
  3. Open a command-line terminal in this folder, and run:
    • npm install keythereum
    • node run.js

Contents of run.js:

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

const KEYSTORE = "KeystoreFileName";
const PASSWORD = "YourPassword";

const keyObject = JSON.parse(fs.readFileSync(KEYSTORE, {encoding: "utf8"}));
const privateKey = keythereum.recover(PASSWORD, keyObject).toString("hex");
console.log(`0x${keyObject.address}: 0x${privateKey}`);

In the code above, replace:

  • The string "KeystoreFileName" with the key-store file name
  • The string "YourPassword" with your password
Related Topic