keyhunt icon indicating copy to clipboard operation
keyhunt copied to clipboard

Privkey to wif

Open Cyclopas opened this issue 2 years ago • 2 comments
trafficstars

I've create a vanity address. Anyone that wants to convert privkey to wif heres a python code, where private_key_hex set the private key.

import hashlib
import base58

def private_key_to_wif(private_key_hex, compressed=False, prefix=b'\x80'):
    if compressed:
        private_key_hex += '01'
    
    extended_key = prefix + bytes.fromhex(private_key_hex)
    checksum = hashlib.sha256(hashlib.sha256(extended_key).digest()).digest()[:4]
    extended_key_with_checksum = extended_key + checksum
    wif = base58.b58encode(extended_key_with_checksum).decode('utf-8')
    return wif

private_key_hex = ''
wif = private_key_to_wif(private_key_hex, compressed=True)  # Change compressed=False to generate uncompressed WIF
print("Compressed WIF:", wif)

Cyclopas avatar Jul 31 '23 11:07 Cyclopas

Thanks.

Also there is one trusted page to do that, you can download the page and run it on localhost. https://www.bitaddress.org/

albertobsd avatar Jul 31 '23 18:07 albertobsd

Feel free to close it Alberto. Or leave it open just for refence. Thanks for your opensource hard work.

Cyclopas avatar Jul 31 '23 22:07 Cyclopas