forked from andrewschaaf/paper-keys
-
Notifications
You must be signed in to change notification settings - Fork 1
/
KeyTool.java
36 lines (28 loc) · 1.23 KB
/
KeyTool.java
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
import com.google.bitcoin.core.*;
public class KeyTool {
public static void main(String args[]) {
if (args[0].equals("--gen-keys")) {
int n = Integer.parseInt(args[1]);
System.out.println("{\"keys\":[");
for (int i = 0; i < n; i++) {
if (i > 0) {
System.out.println(",");
}
System.out.println("{");
ECKey key = new ECKey();
String priv58 = Base58.encode(key.getPrivKey().toByteArray());
String address = key.toAddress(NetworkParameters.prodNet()).toString();
System.out.println("\"priv58\": \"" + priv58 + "\",");
System.out.println("\"address\": \"" + address.toString() + "\"");
System.out.println("}");
}
System.out.println("]}");
}
else if (args[0].equals("--address-of-priv58")) {
String priv58 = args[1];
ECKey key = new ECKey(Base58.decodeToBigInteger(priv58));
String address = key.toAddress(NetworkParameters.prodNet()).toString();
System.out.println(address);
}
}
}