-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
93 lines (77 loc) · 3.31 KB
/
Program.cs
File metadata and controls
93 lines (77 loc) · 3.31 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.IO;
using NBitcoin;
using Nethereum.Accounts;
using Nethereum.Hex.HexConvertors.Extensions;
namespace GenerateWallets
{
class Program
{
static void Main(string[] args)
{
// Number of BTC and ETH keys to generate
int n = 100;
Console.WriteLine("");
// Generate Bitcoin addresses and private keys
Console.WriteLine("Generating " + n + " BTC addresses & private keys...");
Console.WriteLine("");
string BTCfileName = "C:\\GENKEYS\\BitcoinKeys.csv";
if (!File.Exists(BTCfileName))
{
string header = "ID, BTC address, BTC privateKey, Assigned" + Environment.NewLine;
File.WriteAllText(BTCfileName, header);
}
for (int i = 1; i <= n; i++)
{
try
{
Guid guid = Guid.NewGuid();
Key privateKey = new Key(); // generate a random private key
PubKey publicKey = privateKey.PubKey; // derive public key
var privateKeySecret = privateKey.GetBitcoinSecret(Network.Main);
var address = publicKey.Decompress().GetAddress(Network.Main);
string keys = guid + "," + address + "," + privateKeySecret + ", 0" + Environment.NewLine;
File.AppendAllText(BTCfileName, keys);
Console.WriteLine("BTC address: " + address);
}
catch (Exception x)
{
Console.WriteLine("Error:" + x.Message);
Console.WriteLine("");
}
}
// --------------------------------------------
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
// --------------------------------------------
// Generate Ethereum addresses and private keys
Console.WriteLine("Generating " + n + " ETH addresses & private keys...");
Console.WriteLine("");
string ETHfileName = "C:\\GENKEYS\\EthereumKeys.csv";
if (!File.Exists(ETHfileName))
{
string header = "ID, ETH address, ETH privateKey, Assigned" + Environment.NewLine;
File.WriteAllText(ETHfileName, header);
}
for (int i = 1; i <= n; i++)
{
try
{
Guid guid = Guid.NewGuid();
var ecKey = EthECKey.GenerateKey(); // generate a random private key
var privateKeyAsBytes = ecKey.GetPrivateKeyAsBytes().ToHex(); // derive public key
var address = ecKey.GetPublicAddress();
string keys = guid + "," + address + "," + privateKeyAsBytes + ", 0" + Environment.NewLine;
File.AppendAllText(ETHfileName, keys);
Console.WriteLine("ETH address: " + address);
}
catch (Exception x)
{
Console.WriteLine("Error:" + x.Message);
Console.WriteLine("");
}
}
}
}
}