Get private-keys from wallet using bitcoinj

2

I'm using bitcoinj for transferring bitcoin.

Now I want to export private key of my wallet.

So how can I get the private key from bitcoinj?

Bandish

Posted 2018-09-06T11:15:27.293

Reputation: 23

Answers

0

for address prv key

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

if you want master private key then do something like this

        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());

Zombie

Posted 2018-09-06T11:15:27.293

Reputation: 538

I want private keys of all my generated addresses. Please help if you know. – Bandish – 2018-10-03T06:00:46.073

@BandishMehta please accept the answer if it satisfied your question, because otherwise it remains "unanswered" on the site :) – Zombie – 2018-10-03T09:01:21.663