-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
55 lines (41 loc) · 2.24 KB
/
Copy pathProgram.cs
File metadata and controls
55 lines (41 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Linq;
using System.Runtime.InteropServices;
using NBitcoin;
using NBitcoin.DataEncoders;
// ReSharper disable All
namespace BitcoinAddress
{
class Program
{
static void Main()
{
//Bitcoin Address is what you share to the world to get paid
//-> All i need is address to send $$$
//Use this key to spend $$$, and no need to access to the internet
Key privateKey = new Key(); // generate a random private key
Console.WriteLine($"Here is the privateKey looks like **{privateKey.ToString()}");
//From here use one way crypto to generate public key
PubKey publicKey = privateKey.PubKey;
Console.WriteLine($"One way gen public key from privateKey **{publicKey}"); // 0251036303164f6c458e9f7abecb4e55e5ce9ec2b2f1d06d633c9653a07976560c
//There are 2 Mian Bitcoin Networks
// - TestNet -> Get free coins to test, no big deal
// - MainNet
//This is how I get the address from TestNet and MainNet & get paid!! yahooo...
Console.WriteLine(publicKey.GetAddress(Network.Main)); // 1PUYsjwfNmX64wS368ZR5FMouTtUmvtmTY
Console.WriteLine(publicKey.GetAddress(Network.TestNet)); // n3zWAo2eBnxLr3ueohXnuAa8mTVBhxmPhq
//**Proper way to get the bitcoin address
//Fact: The hash of the public key is generated by performing a
//SHA256 hash on the public key, and then performing a RIPEMD160 hash
//on the result, with Big Endian notation.
//The function could look like this: RIPEMD160(SHA256(pubkey))
var publicKeyHash = publicKey.Hash;
Console.WriteLine("Generate to get bitcoin address "+publicKeyHash); // f6889b21b5540353a29ed18c45ea0031280c42cf
var mainNetAddress = publicKeyHash.GetAddress(Network.Main);
var testNetAddress = publicKeyHash.GetAddress(Network.TestNet);
Console.WriteLine($"The MainNet Address {mainNetAddress}"); // 1PUYsjwfNmX64wS368ZR5FMouTtUmvtmTY
Console.WriteLine($"The TestNet Address {testNetAddress}"); // n3zWAo2eBnxLr3ueohXnuAa8mTVBhxmPhq
Console.ReadLine();
}
}
}