2

I just generated new Ethereum account with

geth account new
Your new account is locked with a password. Please give a password. Do not forget this password.
Password:
Repeat password:

Your new key was generated

Public address of the key:   0xE582f436A505EEe5E2D8F2F70752e876F51abC0C
Path of the secret key file: /Users/user/Library/Ethereum/keystore/...--e582f436a505eee5e2d8f2f70752e876f51abc0c

- You can share your public address with anyone. Others need it to interact with you.
- You must NEVER share the secret key with anyone! The key controls access to your funds!
- You must BACKUP your key file! Without the key, it's impossible to access account funds!
- You must REMEMBER your password! Without the password, it's impossible to decrypt the key!

Now what exactly here in this JSON is private key?

I have found https://github.com/ethereumjs/keythereum that say geth is using

key derivation functions (PBKDF2-SHA256 or scrypt), symmetric ciphers (AES-128-CTR or AES-128-CBC)

That is again more confusing, as private key should be long number

If private key is encrypted how to decrypt and see it?

{
  "address": "e582f436a505eee5e2d8f2f70752e876f51abc0c",
  "crypto": {
    "cipher": "aes-128-ctr",
    "ciphertext": "19f04d75a17df3f6310f934628358ebb137e4b64eb4e320e5df5991d7739e131",
    "cipherparams": {
      "iv": "b6f5905c11bda21b4fcd68dc1b6e0cb4"
    },
    "kdf": "scrypt",
    "kdfparams": {
      "dklen": 32,
      "n": 262144,
      "p": 1,
      "r": 8,
      "salt": "1c9005124e67c5cee8cc469b85274c8fde2bc204dcfc9262b49389172231c4d5"
    },
    "mac": "0ef27b22356a8cb01b5dfab025132b56033a5f2e6c55e21ffca8c5036e19f85f"
  },
  "id": "54741ac3-7f23-46f9-b2fd-d7358af5ec76",
  "version": 3
}

More theory is in How are ethereum addresses generated?

2 Answers 2

4

When you generate the keystore using geth account new, it ask you for your password. To put it in simple term, the private key was encrypted using the password, and the result is the "ciphertext": "19f04d75a17df3f6310f934628358ebb137e4b64eb4e320e5df5991d7739e131". So it is just another encryption layer.

You can convert (keystore + password) -> private key programmatically, but if you are lazy, you can import the keystore to metamask, and then export the private key.

2

Using Nose.js

Viet doesn't say how to "convert (keystore + password) -> private key programmatically", but it seems to be possible with Node.js with the function keythereum.recover(..):

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

const KEYSTORE_DIR  = "The full path of your keystore folder";
const PASSWORD_FILE = "The full path of your password file";

for (const file of fs.readdirSync(KEYSTORE_DIR)) {
    const keyObject  = JSON.parse(fs.readFileSync(KEYSTORE_DIR + "/" + file, "utf8"));
    const publicAddr = keyObject.address;
    const privateKey = keythereum.recover(fs.readFileSync(PASSWORD_FILE), keyObject).toString("hex");
    console.log(`0x${publicAddr}: 0x${privateKey}`);
}

Source: https://ethereum.stackexchange.com/a/72342/91560

Impossible with geth

It seems to be impossible with geth:

"geth" does not offer commands to export private key out of an Ethereum account. If you really want to get the private key, you can import the keystore file to MetaMask wallet. You can then export the private key from MetaMask wallet.

Your Answer

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

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