Wallet Import Format (WIF, also known as Wallet Export Format) is a way of encoding a private ECDSA key to make it easier to copy (en.bitcoin.it, 2013). We will discuss how to do this step by step below.

The private key to WIF

1 – Take a private key

2 – Add a 0×80 byte in front of it for mainnet addresses or 0xef for testnet addresses. Also, add a 0×01 byte at the end of the private key will correspond to a compressed public key.

3 – Perform SHA-256 hash on the extended key

4 – Perform SHA-256 hash on the result of the SHA-256 hash

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 a base58 string using Base58Check encoding. This is the Wallet Import Format

WIF to private key

1 – Take a Wallet Import Format string

2 – Convert it to a byte string using Base58Check encoding

3 – Drop the last 4 checksum bytes from the byte string

4 – Drop the first byte (it should be 0×80). If the private key corresponds to a compressed public key, drop the last byte (0×01). If it corresponded to a compressed public key, the WIF string would have started with K or L instead of 5 (or c instead of 9 on testnet). This is the private key.

WIF checksum checking

1 – Take the Wallet Import Format string

2 – Convert it to a byte string using Base58Check encoding

3 – Drop the last 4 checksum bytes from the byte string

3 – Perform SHA-256 hash on the shortened string

4 – Perform SHA-256 hash on the result of the SHA-256 hash

5 – Take the first 4 bytes of the second SHA-256 hash. This is the checksum.

6 – Make sure it is the same, as the last 4 bytes from point 2

7 – If they are, and the byte string from point 2 starts with 0×80 (0xef for testnet addresses), there is no error.

GENERATOR TOOLS
TP’s Go Bitcoin Tests – located at http://gobittest.appspot.com/PrivateKey
SHA256 Hash Generator – located at https://www.xorbin.com/tools/sha256-hash-calculator
Base58 Encoder/Decoder/Validator – located at http://lenschulwitz.com/base58

Feedback

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.

Post your comment on this topic.

Post Comment