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,740 points
2,068 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,350 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,740 points
890 views
+1 vote
0 answers

How to generate bitcoin address from XPUB

How to generate bitcoin addresses from XPUB ...READ MORE

Mar 9, 2022 in Blockchain by Soham
• 9,700 points
1,426 views
0 votes
1 answer

How to get Bitcoin Private Key from an ExtPrivKey using NBitcoin

From what I see in the code ...READ MORE

answered Apr 7, 2022 in Blockchain by Aditya
• 7,680 points
998 views
0 votes
1 answer

Generate Ethereum addresses in HD Wallet using public key only (bitcoinj/web3j)

Like Bitcoin, Ethereum uses secp256k1. Ethereum addresses ...READ MORE

answered Apr 12, 2022 in Blockchain by Soham
• 9,700 points
3,248 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,350 points
1,618 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
1,663 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,740 points
43,813 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,350 points
1,017 views
+1 vote
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,350 points
823 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP