BitcoinJ generate address from private key

0 votes

I'm facing an issue regarding generating address from private key.

I got the master private key from electrum and from bitcoin core that starts from

xprv9s21xxxxxxxxxxxxxxxxxxxxxxxxxxxx

in bitcoinJ:

ECKey key=ECKey.fromPrivate(prv); // it accepts bytes[] or BigInteger

how can i convert 9s21xxxxxxxxxxxxxxxxx into bytes[] or BigInteger.

Try:

String prvkey=9s21xxxxxxxxxxxxxxxxxxxxx
BigInteger bytes=new BigInteger(priv,16);

it throws exception as it can't convert due to number format.

Try 2:

byte[] bytes=prvkey.getBytes(StandardCharsets.UTF_16);

it generates valid address from ECKey and i send transaction to that address via electrum. but wallet didn't receive money. 

What should i do to convert master private key into BigInteger or bytes[]

Sep 4, 2018 in Blockchain by digger
• 26,550 points
265 views

1 answer to this question.

0 votes

Convert string private key into bytes[]:

ECKey key = ECKey.fromPrivate(prv.getBytes());

Or, convert string private key into BigInteger:

BigInteger privKey = Base58.decodeToBigInteger(prv);
ECKey key = ECKey.fromPrivate(privKey);
answered Sep 4, 2018 by slayer
• 29,050 points

Related Questions In Blockchain

0 votes
1 answer

Not able to generate WIF from extended private key

I found the answer to this in the ...READ MORE

answered Aug 29, 2018 in Blockchain by digger
• 26,550 points
62 views
0 votes
1 answer

How can I retrieve to and from address in transaction directly from blockchain?

The spending conditions, i.e., who is able ...READ MORE

answered Jul 11, 2018 in Blockchain by Shashank
• 10,350 points
69 views
0 votes
1 answer

How to generate new address for blockchain wallet?

You can use the following to generate ...READ MORE

answered Jul 16, 2018 in Blockchain by digger
• 26,550 points
85 views
0 votes
1 answer

Bitcoinj send payment from a wallet

The problem actually was with the input ...READ MORE

answered Sep 6, 2018 in Blockchain by slayer
• 29,050 points
121 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
140 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,550 points
3,022 views
0 votes
1 answer

Bitcoin private key: translate from bash to perl

use bignum; # Get arbitrary precision arithmetic # ...READ MORE

answered Sep 4, 2018 in Blockchain by slayer
• 29,050 points
180 views
0 votes
1 answer

How to generate Bitcoin address?

Convert the hex string back to bytes ...READ MORE

answered Aug 20, 2018 in Blockchain by slayer
• 29,050 points
69 views