How can I take the output of sha256sum

sudofox@ubuntu:~$ echo -n 'Hi guys!' | sha256sum
7542fb6685f9fd8f37d56faf62f0bb4563684a51539e4b26f0840db361e0027c  -

and turn it into a Base58Check encoded private key?

I need to be able to do this with a list of SHA256 keys. Is there a script I can download, or must I spend a few weeks making it just so I can make my temporary addresses?

In response to first comment: No, I must input a string, like "fluttershy", for example, into sha256sum and then I must encode the output of sha256sum into a base58check private key.

string -->sha256sum --> some automagic process, which is the purpose of this question --> bitcoin private key.

Update: For anyone wanting to use Grondilu's Bitcoin Bash Tools: You need to source the bitcoin.sh file after extracting it into your directory to use the functions.

source ./bitcoin.sh

Update 2 (Aug 2017): Rewrote script to go from step 1 to WIF in one go. You can just add the declaration of base58 and the encodeBase58 functions from bitcoin.sh if you want to skip the rest of the lib.

#Tool to convert bitcoin privkeys into WIF keys
# by sudofox

source ./bitcoin.sh

KEY=$1 # first arg

# add 0x80 to beginning
FIRSTHASH=$(echo -n "$EXTENDEDKEY" |xxd -r -p |sha256sum -b|awk '{print $1}')
SECONDHASH=$(echo -n "$FIRSTHASH" |xxd -r -p |sha256sum -b|awk '{print $1}')
CHECKSUM=$(echo $SECONDHASH|cut -c1-8)
echo $FINAL

The usage would be

./sha256_to_privkey.sh key

where in my example (see Stephen Gornick's answer), key would be


Do the same thing for the various functions, modifying as needed. Hope this helps anyone struggling to use the tools.

  • Yes, this is possible. But I have a strong feeling this is an XY problem – Nick ODell Mar 9 '13 at 3:36
  • Clarification (well, stating in explicit terms) above. – Austin Burk Mar 9 '13 at 3:50
  • Is there some reason why you want to send your bitcoins to an unspendable public key? – Nick ODell Mar 9 '13 at 4:08
  • @Nick ODell "Unspendable public key?" I'm generating a bitcoin private key. That means it would be spendable as long as I still have the key I generated. You changed the title of my question so that it looks like I want to hash the private key and then try to turn that into a bitcoin address. Why would I want to do that? I'm changing the title to "How can I convert a SHA256 hash into a Bitcoin base58 private key?" – Austin Burk Mar 9 '13 at 5:04

What you are requesting is described as computing the Wallet Import Format for that private key:

Using your example:

1.) Take a private key (Below is the HEX representation of binary value)


2.) Add a 0x80 byte in front of it


3.) Perform SHA-256 hash on the extended key

$ echo -n '807542FB6685F9FD8F37D56FAF62F0BB4563684A51539E4B26F0840DB361E0027C' | xxd -r -p | sha256sum -b


4.) Perform SHA-256 hash on result of SHA-256 hash

$ echo -n '7DE4708EB23AB611371BB778FC0C8BDE80394AB2D8704D7129FB5771E2F1730D' | xxd -r -p | sha256sum -b


5.) Take the first 4 bytes of the second SHA-256 hash, this is the checksum


6.) Add the 4 checksum bytes from point 5 at the end of the extended key from point 2


7.) Convert the result from a byte string into Base58 to get it into the Base58Check format. This is also known as the Wallet Import Format

(Converted from point 6 to base58 using https://bitcointools.appspot.com, or using encodeBase58 from https://github.com/grondilu/bitcoin-bash-tools)


  • A handy utility that does each step: gobittest.appspot.com/PrivateKey – Stephen Gornick Mar 9 '13 at 5:10
  • This looks pretty good! I'll give it a shot Sunday (we're going 'cross state to see frozen waves tomorrow). Expect an 'accepted' soon! Oh, and very useful links. – Austin Burk Mar 9 '13 at 5:18
  • Thank you very much. Everything's working really well now. For future reference to anyone wanting to use Grondilu's Bitcoin Bash Tools: Source bitcoin.sh after extracting it into your directory. – Austin Burk Mar 11 '13 at 1:04
  • 1
    The wording of step 7 is a little misleading. You've already added the checksum in step 6, so in step 7 you should convert the hex to Base58, not Base58Check. Brainwallet.org has a converter. You can download the brainwallet source code from github and run it offline. – kellrobinson Nov 10 '14 at 0:21
  • on Step 7 Convert the hex string back into bytecode before running it through base58...that step isn't very clear...Also I found that I had to decode my hex values back into bytecode for the sha digests but to then encode them back into hex so they were readable to my console (using python) – Frankenmint Mar 20 '16 at 11:02

If you don't want to compute the key manually, there's a useful command-line utility for this called bitcoin-tool:

$ ./bitcoin-tool \
  --input-file <(echo -n 'Hi guys!' | openssl dgst -sha256 -binary) \
  --input-format raw \
  --input-type private-key \
  --network bitcoin \
  --output-type private-key-wif \
  --output-format base58check \
  --public-key-compression uncompressed

Passing --output-type all yields even more interesting output:

  • idk how i missed it, but this is one way to get address to hash160 hex., public-key-ripemd160.hex:a25b865343d3fcc08994005f496265b48349e363 – AMB Oct 12 '17 at 6:03

protected by Community Feb 3 '17 at 4:58

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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