Bitcoinj

使用 bitcoinj 從錢包中獲取私鑰

  • November 24, 2018

我正在使用 bitcoinj 傳輸比特幣。

現在我想導出我錢包的私鑰。

那麼如何從bitcoinj獲取私鑰呢?

用於地址 prv 密鑰

 void key(){
       ECKey key = new ECKey();
       Address pubAddress = new Address(NetworkParameters.prodNet(), key.getPubKeyHash());
       DumpedPrivateKey privKey = key.getPrivateKeyEncoded(NetworkParameters.prodNet());
       System.out.println("Public address: " + pubAddress.toBase58() + "; Private key: " + privKey.toBase58());
}

如果你想要主私鑰然後做這樣的事情

       NetworkParameters params = NetworkParameters.prodNet();
       Wallet wallet= new Wallet(params);

       DeterministicKey watchingKey = wallet.getWatchingKey();

       // Get the standardised base58 encoded serialization
       System.out.println("Watching key data: " + watchingKey.serializePubB58(params));
       System.out.println("Watching key birthday: " + watchingKey.getCreationTimeSeconds());

引用自:https://bitcoin.stackexchange.com/questions/78959