0% found this document useful (0 votes)
859 views1 page

Convert WIF Keys

The document discusses converting a 256-bit private key to a Wallet Import Format (WIF) key and vice versa. It provides code to convert a sample 256-bit private key to a WIF key. However, when attempting to reverse the process and convert a WIF key back to the original 256-bit private key, it results in a TypeError. The error occurs because base58.b58decode expects a bytes-like object, not a string.

Uploaded by

Paul Phoneix
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
859 views1 page

Convert WIF Keys

The document discusses converting a 256-bit private key to a Wallet Import Format (WIF) key and vice versa. It provides code to convert a sample 256-bit private key to a WIF key. However, when attempting to reverse the process and convert a WIF key back to the original 256-bit private key, it results in a TypeError. The error occurs because base58.b58decode expects a bytes-like object, not a string.

Uploaded by

Paul Phoneix
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Convert WIF Keys

I am aware how to convert the private key into WIF format in python, now I am trying to reverse
this process and convert a WIF formatted private key back into a 256-bit private key, following
this guide: https://en.bitcoin.it/wiki/Wallet_import_format

This is the code to convert from 256-bit private key into WIF format:

import hashlib
import base58
import binascii

private_key_static =
"0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D"
extended_key = "80"+private_key_static
first_sha256 = hashlib.sha256(binascii.unhexlify(extended_key)).hexdigest()
second_sha256 = hashlib.sha256(binascii.unhexlify(first_sha256)).hexdigest()

# add checksum to end of extended key


final_key = extended_key+second_sha256[:8]

# Wallet Import Format = base 58 encoded final_key


WIF = base58.b58encode(binascii.unhexlify(final_key))

print (WIF)
Now my attempt to reverse this process looks like this:

import hashlib
import base58
import binascii

private_key_WIF = 5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ
first_encode = base58.b58decode(binascii.hexlify(private_key_WIF))
print (first_encode)
Instead of receiving the byte string, I get following error:

TypeError: a bytes-like object is required, not 'str'


(All private keys used are sample keys taken from Bitcoin Wiki.)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy