I want to understand how a bitcoin private key is made up.

Looking at this graphical generator https://royalforkblog.github.io/2014/08/11/graphical-address-generator/#hello

I understand step 1, how the private key is generated: 2CF24DBA5FB0A30E26E83B2AC5B9E29E1B161E5C1FA7425E73043362938B9824

I can see the prepended version number 80, and that I should append the compression flag 01

My question is around step 4, which is simply detailed as "Append checksum. Checksum is the first 4 bytes of double sha256 hash of whatever is being checkedsum'ed."

So I take 802CF24DBA5FB0A30E26E83B2AC5B9E29E1B161E5C1FA7425E73043362938B982401 and double SHA-256, and I don't get anything like the expected checksum of F29E9187

Can anyone help me understand how F29E9187 is derived?


F29E9187 are indeed the first four bytes of the double sha256 of the bytes:


In order to check this, you need to compute the double sha256 of this array of bytes. However, as already discussed, passing the string 802CF2... to the hash function will not yield the right answer, as this string is not the array of bytes itself (it is a hexadecimal encoding of the array). So let us create a binary file which corresponds to the hex encoding above:

$ echo -n 802CF24DBA5FB0A30E26E83B2AC5B9E29E1B161E5C1FA7425E73043362938B982401 \
   | xxd -r -p > temp

Let us check our binary file temp has the correct bytes:

$ hexdump -C temp

00000000  80 2c f2 4d ba 5f b0 a3  0e 26 e8 3b 2a c5 b9 e2  |.,.M._...&.;*...|
00000010  9e 1b 16 1e 5c 1f a7 42  5e 73 04 33 62 93 8b 98  |....\..B^s.3b...|
00000020  24 01                                             |$.|

So far so good. We can now compute the first sha256 hash of these bytes:

$ sha256sum temp
08a9d3e1296633b2a4071316eaf597f1c93a0ec2f4b68b24c6e0ad2e7c06540c  temp

Again, we are faced with a hex encoding which we need to convert to actual bytes:

$ echo -n 08a9d3e1296633b2a4071316eaf597f1c93a0ec2f4b68b24c6e0ad2e7c06540c \
  | xxd -r -p > temp

Checking once more:

$ hexdump -C temp

00000000  08 a9 d3 e1 29 66 33 b2  a4 07 13 16 ea f5 97 f1  |....)f3.........|
00000010  c9 3a 0e c2 f4 b6 8b 24  c6 e0 ad 2e 7c 06 54 0c  |.:.....$....|.T.|

So let's compute the sha256 hash of these bytes:

$ sha256sum temp
f29e9187a566a24502d7cd2eae948e74bc4dfafc7deff44cce80e1256ef12a3e  temp

you can see that the first 4 bytes are indeed F29E9187.


Also look at this fairly simple brain wallet generator - it shows the steps needed to create the standard base58 private key from a passphrase.

Below is a partial screen capture of the above URL from the site commandlinefu.com:

Screen capture of URL

Also useful - you can use brainwallet.io to cross-check the above results.

protected by Community Dec 2 '17 at 10:56

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.