一个我提供的方法,通过将结果privatekey
导入到MetaMask
中并获得与预期相同的地址来验证:
private static JSONObject process(String seed){
JSONObject processJson = new JSONObject();
try {
ECKeyPair ecKeyPair = Keys.createEcKeyPair();
BigInteger privateKeyInDec = ecKeyPair.getPrivateKey();
String sPrivatekeyInHex = privateKeyInDec.toString(16);
WalletFile aWallet = Wallet.createLight(seed, ecKeyPair);
String sAddress = aWallet.getAddress();
processJson.put("address", "0x" + sAddress);
processJson.put("privatekey", sPrivatekeyInHex);
} catch (CipherException e) {
//
} catch (InvalidAlgorithmParameterException e) {
//
} catch (NoSuchAlgorithmException e) {
//
} catch (NoSuchProviderException e) {
//
}
return processJson;
}
main(){ // unit test
String seed = UUID.randomUUID().toString();
JSONObject result = process(seed); // get a json containing private key and address
}
原文《以太坊常见问题和错误》中的:
http://cw.hubwiz.com/card/c/ethereum-FAQ/1/1/5/
另外推荐几个很受欢迎全网稀缺的互动教程: