JAVA生成BTC地址以及私钥,公钥和助记词

JAVA生成BTC地址以及私钥,公钥和助记词

有用的话,回来给我点个赞,谢谢了。有问题留言,我会尽快回复。

maven依赖



    org.bitcoinj
    bitcoinj-core
    0.14.7

上代码

 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;
    }

后续继续更新btc钱包的其他操作

你可能感兴趣的:(JAVA生成BTC地址以及私钥,公钥和助记词)