Bitcoin Forum
May 11, 2024, 09:58:24 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Trying to convert 256 bit random number to WIF  (Read 317 times)
shahzad73 (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 4


View Profile
August 17, 2018, 05:19:15 PM
Merited by Chris! (1)
 #1

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


1715421504
Hero Member
*
Offline Offline

Posts: 1715421504

View Profile Personal Message (Offline)

Ignore
1715421504
Reply with quote  #2

1715421504
Report to moderator
1715421504
Hero Member
*
Offline Offline

Posts: 1715421504

View Profile Personal Message (Offline)

Ignore
1715421504
Reply with quote  #2

1715421504
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715421504
Hero Member
*
Offline Offline

Posts: 1715421504

View Profile Personal Message (Offline)

Ignore
1715421504
Reply with quote  #2

1715421504
Report to moderator
1715421504
Hero Member
*
Offline Offline

Posts: 1715421504

View Profile Personal Message (Offline)

Ignore
1715421504
Reply with quote  #2

1715421504
Report to moderator
1715421504
Hero Member
*
Offline Offline

Posts: 1715421504

View Profile Personal Message (Offline)

Ignore
1715421504
Reply with quote  #2

1715421504
Report to moderator
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
August 17, 2018, 10:22:33 PM
 #2

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


█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
TheArchaeologist
Sr. Member
****
Offline Offline

Activity: 310
Merit: 727


---------> 1231006505


View Profile WWW
August 17, 2018, 10:31:56 PM
Merited by DarkStar_ (3)
 #3

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

Sooner or later you're going to realize, just as I did, that there's a difference between knowing the path and walking the path
pebwindkraft
Sr. Member
****
Offline Offline

Activity: 257
Merit: 343


View Profile
August 24, 2018, 09:17:27 PM
 #4

base58 handling at the shell level:

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

grondilu rocks!
bob123
Legendary
*
Offline Offline

Activity: 1624
Merit: 2481



View Profile WWW
August 25, 2018, 07: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[])

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!