1. A step to DECODE / ENCODE W.I.F. key
A private key in WIF (Wallet Import Format) follows this structure when the base 58 is decoded:
- The first byte (0x80) is here to indicate the network type (In this case it’s the main network). (uint8_t)
- The 32 next bytes (0x9172e8eec99f144f72eca9a568759580edadb2cfd154857f07e657569493bc44) is your private key. (uint8_t[32])
- The next byte (0x01) is the compression flag. (boolean)
- The next 4 bytes (0x4739a585) is the checksum of all previous data. The checksum used is SHA256d. (uint8_t[4])
Example to create a checksum:
HASH1 = SHA256(80 || 9172e8eec99f144f72eca9a568759580edadb2cfd154857f07e657569493bc44 || 01) (Bytes concatenation)
HASH1 = SHA256(809172e8eec99f144f72eca9a568759580edadb2cfd154857f07e657569493bc4401)
HASH1 = dd777204043c893da5d679703cacd9b7043e11b9b4f7311572759f5902e609cb
HASH2 = SHA256(dd777204043c893da5d679703cacd9b7043e11b9b4f7311572759f5902e609cb)
HASH2 = 4739a585c71b269803c5b5322f30fe01386e705ea8f775b08f6d2c0476d35c97
CHECKSUM = 4739a585
All hashes were done with https://emn178.github.io/online-tools/sha256.html (hex option)
So you can now encode/decode a WIF key.
Note: to encode in WIF structure, you’ll need to convert data above in base58 format. So in order to decode a WIF key, you’ll need to convert base58 data in bytes like written data above.
2. Partial solution to the problem (QrCode generation)
You can now encode your private key in a Wallet Import Format. Then, you’ll be able to create a Qr Code. For example (with the same key used above):
WIF = Base58Encode(809172e8eec99f144f72eca9a568759580edadb2cfd154857f07e657569493bc44014739A585)
WIF = L26SjTSxuXTPTv58MfMErY1wiL46D3CqnqvzQj754yZs6RKkfaVi
QrCode generation with https://www.barcodesinc.com/generator/qr/.
I typed L26SjTSxuXTPTv58MfMErY1wiL46D3CqnqvzQj754yZs6RKkfaVi
and I got this:
3. Warnings
- These steps are useful when you have the 32 bytes of private key. Not when you have the encrypted private key. You need to decrypt it first with the encryption algorithm in which you encrypted your key. This is a delicate step.
- I used a lot websites to encode/decode data. This is not secure but it was a private key used as an educational purpose only. I don’t recommand you to do the same thing with real private key. The solution is to use a software. Like others suggested, there are plenty of. I would certainly advice you to use sparrow since it provides technical functionnalities.
- Among used websites, this one can learn you more about WIF: https://learnmeabitcoin.com/technical/wif.