I use Java and bitcoinj. I have a private key
String str="5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf";
I try to get compress and decompress 2 adresses in this format:
1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH
I do the first step, try get ECKey:
NetworkParameters params = MainNetParams.get();
ECKey key;
if (str.length() == 51 || str.length() == 52) {
DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, str);
key = dumpedPrivateKey.getKey(); //ERROR
} else {
BigInteger privKey = Base58.decodeToBigInteger(str);
key = ECKey.fromPrivate(privKey);
}
.
.
.
and I get an exception:
Exception in thread "main" java.lang.IllegalArgumentException
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:128)
at org.bitcoinj.core.ECKey.<init>(ECKey.java:195)
at org.bitcoinj.core.ECKey.fromPrivate(ECKey.java:243)
at org.bitcoinj.core.ECKey.fromPrivate(ECKey.java:259)
at org.bitcoinj.core.DumpedPrivateKey.getKey(DumpedPrivateKey.java:101)
at com.example.demo2.controllers.AdressFromKey.main(AdressFromKey.java:35)
What am I doing wrong?
I am trying to generate these keys https://keys.lol/bitcoin/407532363493837873358792558699156305516644599981797776434520630335882679096
and get the corresponding addresses. They all knock out a bug.
Maybe there is some way to hardcode and get these addresses without libraries?
– Samanta Fox Nov 29 '21 at 07:04