How to get private key from account address and password?

  • What I have
    1. I am able to create new account with personal.newAccount() method of web3 api.
    2. I am working on my private blockchain.
    3. geth node start with following command:-
    geth --datadir ~/privateBlockChain1 --networkid 1300 --rpcport 8002 --port 30301 --rpcapi="db,eth,net,web3,personal,admin,txpool,debug" --rpc --maxpeers 0 --nodiscover --targetgaslimit 110000000000 --dev --rpccorsdomain "*" --rpcaddr "" console
    4. I am using web3 api and ethereumjs-wallet npm api.
    5. Keystore file is successfully store in private blockchain directory.

    What I want
    1. I want to get private key of respective account.
    2. actually, i want to get all data of keystore file of respective account from my nodejs side and will be able to save in my regular database.

    Case 1:
    1. when i create account with personal.newAccount() method with password, how to get private key, if i got private key, then i will be use that key to get all keystore data by following code:---

       var Wallet = require('ethereumjs-wallet');  
        var Key=Buffer.from('account_privatekey','hex');  
        var wallet = Wallet.fromPrivateKey(Key);  
        var json=wallet.toV3String(user_define_password);  // it will return keystore object data. 

    but i am unable to get actual private key from account address and password.
    ` Case 2:
    1. suppose i create private key by following code:-

         var Wallet = require('ethereumjs-wallet');  
            var privateKey=Wallet.generate(password)._privKey;  
            var wallet = Wallet.fromPrivateKey(privateKey);  
            var json=wallet.toV3String(password); // it will get keystore data      `
      2. account creation on my private blockchain this way   
               `  personal.importRawKey(key,password)  
              but error showing like , importRawKey not a function `

    How to fix these

    Isn't it the case that the whole point of a private key is that you cannot get it from the account address and password? The private key is on your hard drive somewhere, but the whole point of the security of public/private keys is that you cannot get it--even if you spent an near-infinite amount of computing resources--from the public key.

    you should add --rpcapi "personal"

  • I used this code to recover the private key from account address and password. firstly, install Keythereum:

    npm install keythereum

    Keythereum is a JavaScript tool to generate, import and export Ethereum keys. read the documentation: GitHub Link

    and this is my code:

    var keythereum = require("keythereum");
    var datadir = "/home/super/.ethereum/rinkeby";
    var address= "0xc8096d713000002c77e4eb62f0000ead5f105a7e";
    const password = "mypass";
    var keyObject = keythereum.importFromFile(address, datadir);
    var privateKey = keythereum.recover(password, keyObject);
  • How to get private key from account address and password?

    One of the founding notions of public/private key cryptography is that what you are describing should be impossible. No cryptographic system in existence would be trusted if you could reverse engineer the private key from the public address.

    So not only is it impossible, but it should be impossible.

    You state:

    when i create account with personal.newAccount() method with password, how to get private key, if i got private key, then i will be use that key to get all keystore data by following code:---

    Are you ask for the directory location of your keystore? If so this may answer your question : Getting private keys of geth accounts

    Also see :

    Everything geth persists gets written inside its data directory (except for the PoW Ethash DAG, see note below). The default data directory locations are platform specific:

    • Mac: ~/Library/Ethereum
    • Linux: ~/.ethereum
    • Windows: %APPDATA%/Ethereum

    Accounts are stored in the keystore subdirectory. The contents of this directories should be transportable between nodes, platforms, implementations (C++, Go, Python).

    The password is used to decrypt the keystore, and thus, the private key. So not only is it not impossible, but it HAS to be possible otherwise the wallet won't be able to spend funds. The OP has clearly stated that the account was created on the same node where he is entering the password.

    this is not the answer to the question, downvote

  • Private key is often required to import your account in a different wallet. Even Metamask needs a private key to import the account. This is how I was able to extract the private key from the node where I created my account. Ethereum keys in a Linux node will be encrypted and stored in the following location.

    ~/.ethereum/keystore/ (mainnet)
    ~/.ethereum/rinkeby/keystore/ (rinkeby testnet)

    If you have the public address of the account and the password used to lock the account, you should be able to extract the private key. I used web3 python package to extract the private key. Install this using pip.

    pip install web3

    Execute the following code

    >>> from import w3
    >>> with open("~/.ethereum/rinkeby/keystore/UTC--2018-06-
         as keyfile:
    ...     encrypted_key =
    ...     private_key = w3.eth.account.decrypt(encrypted_key, 

    UTC--2018-06-10T05-43-22.134895238Z--9e63c0d223d9232a4f3076947ad7cff353cc1a28 is the file containing stored key. This will return a private key in byte format.

    You can get the private key in hex format as follows.

    import binascii
  • You cannot get the private key from the address and password. But you can get the private key from the keyfile and the password, which should work in your case, as I understand the question. For more information on how to get the private key from the keyfile see here.

  • The answer to your question is here:

    Change the filename , password add a line to print the private key to the console and run

    go build ./keystore_passphrase_test.go
  • You can try to brute-force the private key and check if it matches the public key in mind. It will take you some time because it's designed to be mathematically impossible. Have a look at

    It's designed to be infeasible (based on our current understanding of mathematics and physics), not mathematically impossible. I guess this comment also applies to the other answer provided.

  • I found this because I'm trying to export a private key - which I can fully use to send transfers inside geth - so that I can load it into an android app. For that, I noticed that you can download MyEtherWallet from GitHub and run it locally on your machine. You can then safely (as it's all local to your PC) import the geth keystore JSON into that offline MEW and use MEW to decrypt the wallet and show you the private key.

  • I wrote this Go program to export the private key in Hex format:

    package main
    import (
    func main() {
        keyjson,e:=ioutil.ReadFile(inPath); if e != nil { panic(e) }
        key,e:=keystore.DecryptKey(keyjson,password); if e != nil { panic(e) }
        e=crypto.SaveECDSA(outPath,key.PrivateKey); if e!=nil { panic(e) }
        fmt.Println("Key saved to:",outPath)

    I build it like this:

    go build showkey.go

    I run it like this:


    It produces an output file that looks like this (i changed some of the numbers):

    $ cat key.hex 

    I am able to import the resulting private key into MetaMask.

    How do i get `UTC--2018-11-05T16-07-58.071516100Z--21f2bda7bb26e113687ca8827fac1966a68e8b4c` from given address?

    The `UTC--...` thing is the filename of the ethereum wallet.

  • If you prefer a commandline tool written in golang:

    ethereal account keys --address=ADDRESS --passphrase=PASS

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM