Author

Topic: Trying to convert 256 bit random number to WIF (Read 339 times)

legendary
Activity: 1624
Merit: 2481
August 25, 2018, 02:15:39 AM
#5
If you are only stuck at base58, you might want to check out this: https://github.com/adamcaudill/Base58Check


This is a C# implementation of Base58 checked encoding. You'll be able to call it like this:
Code:
Base58Check.EncodePlain(byte[])
sr. member
Activity: 257
Merit: 343
base58 handling at the shell level:

https://github.com/grondilu/bitcoin-bash-tools/blob/master/bitcoin.sh

grondilu rocks!
sr. member
Activity: 310
Merit: 727
---------> 1231006505
You could do so in a few lines of python:

Code:
import os, binascii, hashlib, base58
fullkey = "80"+"7542FB6685F9FD8F37D56FAF62F0BB4563684A51539E4B26F0840DB361E0027C"
sha256a = hashlib.sha256(binascii.unhexlify(fullkey)).hexdigest()
sha256b = hashlib.sha256(binascii.unhexlify(sha256a)).hexdigest()
WIF = base58.b58encode(binascii.unhexlify(fullkey+sha256b[:8]))
print(WIF)

Which outputs the WIF as:
Code:
5JhvsapkHeHjy2FiUQYwXh1d74evuMd3rGcKGnifCdFR5G8e6nH
HCP
legendary
Activity: 2086
Merit: 4361
Have a look here: https://github.com/TangibleCryptography/Secp256k1

It's a Bitcoin private/public key and address library coded in C#. Seems fairly complete.

Note that I haven't personally tested this, but it should at least point you in the right direction Wink

newbie
Activity: 3
Merit: 4
I want to convert a randomly generated 256 bitcoin address into WIF.   I have following step by step instructions that i am trying to implement into C# but could not do so yet. the biggest problem is conversion of string into base58. Can somebody help me do this


1.) Take a private key (Below is the HEX representation of binary value)
7542FB6685F9FD8F37D56FAF62F0BB4563684A51539E4B26F0840DB361E0027C

2.) Add a 0x80 byte in front of it
807542FB6685F9FD8F37D56FAF62F0BB4563684A51539E4B26F0840DB361E0027C

3.) Perform SHA-256 hash on the extended key
$ echo -n '807542FB6685F9FD8F37D56FAF62F0BB4563684A51539E4B26F0840DB361E0027C' | xxd -r -p | sha256sum -b
7DE4708EB23AB611371BB778FC0C8BDE80394AB2D8704D7129FB5771E2F1730D

4.) Perform SHA-256 hash on result of SHA-256 hash
$ echo -n '7DE4708EB23AB611371BB778FC0C8BDE80394AB2D8704D7129FB5771E2F1730D' | xxd -r -p | sha256sum -b
CD5C4A8E03DFBB0E3AA021C2D74A9EAA43CE4C9CB1B20FC88729A7A5834141CA

5.) Take the first 4 bytes of the second SHA-256 hash, this is the checksum
CD5C4A8E

6.) Add the 4 checksum bytes from point 5 at the end of the extended key from point 2
807542FB6685F9FD8F37D56FAF62F0BB4563684A51539E4B26F0840DB361E0027CCD5C4A8E

7.) Convert the result from a byte string into Base58 to get it into the Base58Check format. This is also known as the Wallet Import Format


Jump to: