Skip to content

Commit fc5f740

Browse files
committed
Hashing byte[] seed
1 parent 0a50a51 commit fc5f740

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ And this project includes below external libraries.
3535
* bitcoinj core v0.15.10
3636
* web3j core v4.8.7
3737

38-
Download and use 'ecdsa-keygen-java-1.3.jar' in 'release' tab or [here](release/).
38+
Download and use 'ecdsa-keygen-java-1.4.jar' in 'release' tab or [here](release/).
3939

4040
```sh
41-
implementation files('./ecdsa-keygen-java-1.3.jar')
41+
implementation files('./ecdsa-keygen-java-1.4.jar')
4242
```
4343

4444
## BTCKeyPair
@@ -74,8 +74,8 @@ import com.wuin.ecdsakeyj;
7474
### Create New KeyPair
7575

7676
```java
77-
BTCKeyPair btcKeyPair = new BTCKeyPair();
78-
ETHKeyPair ethKeyPair = new ETHKeyPair();
77+
BTCKeyPair btcKeyPair = BTCKeyPair.create();
78+
ETHKeyPair ethKeyPair = ETHKeyPair.create();
7979

8080
System.out.println(btcKeyPair.getPrivateKey());
8181
System.out.println(btcKeyPair.getPublicKey());
@@ -101,8 +101,8 @@ Note that the result is up to each keypair.
101101
String btcPriv = "Ky7uryfGoK4wnNPXEP71yeM64HN4KKhhvV4Kn7VZyHovcpatNkQX";
102102
String ethPriv = "4ca85fd2d908a77e5b6e5d15e222ae70d1d70c5101cd880a7e2ff2796c6d56ac";
103103

104-
BTCKeyPair btcKeyPair = new BTCKeyPair(btcPriv, false);
105-
ETHKeyPair ethKeyPair = new ETHKeyPair(ethPriv);
104+
BTCKeyPair btcKeyPair = BTCKeyPair.fromPrivateKey(btcPriv);
105+
ETHKeyPair ethKeyPair = ETHKeyPair.fromPrivateKey(ethPriv);
106106

107107
System.out.println(btcKeyPair.getPrivateKey());
108108
System.out.println(btcKeyPair.getPublicKey());
@@ -124,11 +124,16 @@ wRcd8Nkcss8ChuCAQnK6CEevaPTXnCdikVvTH3eNd7DJ
124124

125125
```java
126126
String seed = "This is a seed to create new BTCKePair";
127+
byte[] bseed = seed.getBytes(StandardCharsets.UTF_8);
127128

128-
BTCKeyPair btcKeyPair = new BTCKeyPair(seed, true);
129+
BTCKeyPair btcKeyPair = BTCKeyPair.fromSeed(seed);
130+
BTCKeyPair sbtcKeyPair = BTCKeyPair.fromSeed(bseed);
129131

130132
System.out.println(btcKeyPair.getPrivateKey());
131133
System.out.println(btcKeyPair.getPublicKey());
134+
135+
System.out.println(sbtcKeyPair.getPrivateKey());
136+
System.out.println(sbtcKeyPair.getPublicKey());
132137
```
133138

134139
-must print,
@@ -141,8 +146,8 @@ mxfoQxXkbvfenQmeFXqzY5gvMY3KnTaPvGHkyhhQnRZb
141146
### Sign Message with KeyPair
142147

143148
```java
144-
BTCKeyPair btcKeyPair = new BTCKeyPair();
145-
ETHKeyPair ethKeyPair = new ETHKeyPair();
149+
BTCKeyPair btcKeyPair = BTCKeyPair.create();
150+
ETHKeyPair ethKeyPair = ETHKeyPair.create();
146151

147152
String msg = "Hello, world!";
148153

lib/src/main/java/com/wuin/ecdsakeyj/BTCKeyPair.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package com.wuin.ecdsakeyj;
1414

1515
import java.math.BigInteger;
16+
import java.nio.charset.StandardCharsets;
1617
import java.util.Arrays;
1718

1819
import org.bitcoinj.core.*;
@@ -35,7 +36,8 @@ private BTCKeyPair(String priv) {
3536
}
3637

3738
private BTCKeyPair(byte[] seed) {
38-
byte[] shb = Base58.encode(seed).getBytes();
39+
byte[] sh = Util.sha3(seed);
40+
byte[] shb = Base58.encode(sh).getBytes();
3941
shb = Arrays.copyOfRange(shb, 0, shb.length - 4);
4042

4143
BigInteger k = new BigInteger(shb);
@@ -63,8 +65,7 @@ public static BTCKeyPair fromPrivateKey(String priv) {
6365
}
6466

6567
public static BTCKeyPair fromSeed(String seed) {
66-
byte[] sh = Util.sha3(seed);
67-
return new BTCKeyPair(sh);
68+
return new BTCKeyPair(seed.getBytes(StandardCharsets.UTF_8));
6869
}
6970

7071
public static BTCKeyPair fromSeed(byte[] seed) {

release/ecdsa-keygen-java-1.4.jar

23.3 MB
Binary file not shown.

0 commit comments

Comments
 (0)