Skip to content

Commit

Permalink
add security
Browse files Browse the repository at this point in the history
  • Loading branch information
TOTOROYang committed Mar 14, 2018
1 parent a8207dc commit 6c6aab4
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/main/java/com/ethjava/Security.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.ethjava;

import com.ethjava.utils.Environment;
import org.web3j.crypto.CipherException;
import org.web3j.crypto.Credentials;
import org.web3j.crypto.ECKeyPair;
import org.web3j.crypto.WalletUtils;
import org.web3j.crypto.*;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.http.HttpService;

import java.io.File;
import java.io.IOException;
import java.io.*;
import java.math.BigInteger;
import java.net.URL;

public class Security {
private static Web3j web3j;
Expand All @@ -24,6 +21,9 @@ public static void main(String[] args) {
importPrivateKey(new BigInteger("", 16),
"yzw",
WalletUtils.getTestnetKeyDirectory());

exportBip39Wallet(WalletUtils.getTestnetKeyDirectory(),
"yzw");
}

/**
Expand Down Expand Up @@ -64,4 +64,20 @@ private static void importPrivateKey(BigInteger privateKey, String password, Str
}
}

/**
* 生成带助记词的账号
*
* @param keystorePath
* @param password
*/
private static void exportBip39Wallet(String keystorePath, String password) {
try {
// TODO: 2018/3/14 会抛异常 已经向官方提issue 待回复
Bip39Wallet bip39Wallet = WalletUtils.generateBip39Wallet(password, new File(keystorePath));
System.out.println(bip39Wallet);
} catch (CipherException | IOException e) {
e.printStackTrace();
}
}

}

0 comments on commit 6c6aab4

Please sign in to comment.