JAVA生成BTC地址以及私钥,公钥和助记词
有用的话,回来给我点个赞,谢谢了。有问题留言,我会尽快回复。
maven依赖
<!-- https://mvnrepository.com/artifact/org.bitcoinj/bitcoinj-core -->
<dependency>
<groupId>org.bitcoinj</groupId>
<artifactId>bitcoinj-core</artifactId>
<version>0.14.7</version>
</dependency>
上代码
public static Map newaddress() {
NetworkParameters networkParameters = MainNetParams.get() ;
DeterministicSeed seed = new DeterministicSeed(new SecureRandom(), 128, "", Utils.currentTimeSeconds());
Wallet wallet;
String mnemonics = "";
String privateKey = "";
String publicKey = "";
String address = "";
String pwd = "";
try {
wallet = Wallet.fromSeed(networkParameters, seed);
//私钥
privateKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(networkParameters);
//助记词
mnemonics = wallet.getKeyChainSeed().getMnemonicCode().toString();
publicKey = Hex.toHexString(ECKey.publicKeyFromPrivate(wallet.currentReceiveKey().getPrivKey(), true));
//地址
address = wallet.currentReceiveAddress().toBase58();
} catch (Exception e) {
logger.error("【比特币钱包创建】失败,原因", e);
return null;
}
Map resultMap = new LinkedHashMap();
resultMap.put("mnemonics", mnemonics);
resultMap.put("privateKey", privateKey);
resultMap.put("publicKey", publicKey);
resultMap.put("address", address);
return resultMap;
}