4

I have a simple string, for example test - and I need to convert it to Ethereum private key 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08

What is an algorithm? Which functions should I apply? I want to make it with nodejs.

2
  • 1
    Just to clarify, you want to use the test string as a mnemonic and extract private key from it?
    – OneThunder
    Jul 10, 2022 at 20:40
  • @OneThunder exactly. I wonder how such brain wallets are generated. I know it is not secure to use such private keys, but I am interested for educational purposes.
    – Molfar
    Jul 10, 2022 at 20:44

2 Answers 2

4

You can do it like this using Web3 libraries for programming language:

web3.sha3("my super secret passphrase with a lot of entropy")

You can do it like this on a UNIX/Linux command prompt:

# Needs to have openssl command lines tools installed
printf "supser secret passphra5e" | openssl dgst -sha256
3c37fb6a9605750240461a90d43ca6742b468479a5ec8380113f6be0bb29168b

The only requirement of a private key is that it is 256 bit integer number, or 32 bytes or random data (with some small limitations)

Note that most simple passphares that are guessable are guessed. For example, any sentence from the bible or other famous book is no go.

Check web3.js for JavaScript and web3.py for Python.

2
  • 1
    note sha256 and sha3 are different algorithms which will produce different numbers based on the same string
    – user253751
    Jul 11, 2022 at 9:42
  • 2
    Also it's recommended to use key stretching algorithms like PBKDF2 to counter bruteforce attacks on the key! Using fast Hashing algorithms (like SHA) with poor preimages is not a good idea for key derivation!
    – Anunay
    Jul 11, 2022 at 10:45
1

It’s the simple sha256 encoding.

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.