Title: Trying to convert 256 bit random number to WIF Post by: shahzad73 on August 17, 2018, 05:19:15 PM 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 Title: Re: Trying to convert 256 bit random number to WIF Post by: HCP on August 17, 2018, 10:22:33 PM 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 ;) Title: Re: Trying to convert 256 bit random number to WIF Post by: TheArchaeologist on August 17, 2018, 10:31:56 PM You could do so in a few lines of python:
Code: import os, binascii, hashlib, base58 Which outputs the WIF as: Code: 5JhvsapkHeHjy2FiUQYwXh1d74evuMd3rGcKGnifCdFR5G8e6nH Title: Re: Trying to convert 256 bit random number to WIF Post by: pebwindkraft on August 24, 2018, 09:17:27 PM base58 handling at the shell level:
https://github.com/grondilu/bitcoin-bash-tools/blob/master/bitcoin.sh grondilu rocks! Title: Re: Trying to convert 256 bit random number to WIF Post by: bob123 on August 25, 2018, 07:15:39 AM If you are only stuck at base58, you might want to check out this: https://github.com/adamcaudill/Base58Check (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[]) |