0

How to create a bouncy castle ECPoint from a raw private key hex string? I am getting a private key using the 'dumpprivkey' RPC and removing the header byte and the 4 bytes of checksum + 1 byte of discriminator trailer bytes, resulting in a 32 byte raw key LIKE this example (this sample comes from here). It causes the following exception. Decoding public keys this way does not have this problem.

This is the code:

public static void main(String[] args) {
    String priv_key = "E9873D79C6D87DC0FB6A5778633389F4453213303DA61F20BD67FC233AA33262"; 
    BigInteger value = new BigInteger(priv_key, 16);
    ECCurve BITCOIN_CURVE = new SecP256K1Curve();
    ECPoint point = BITCOIN_CURVE.decodePoint(value.toByteArray());
}

But it results in this exception:

Exception in thread "main" java.lang.IllegalArgumentException: Incorrect length for infinity encoding
    at org.bouncycastle.math.ec.ECCurve.decodePoint(Unknown Source)
    at Btc.main(Btc.java:19)
1

A raw private key is not on the elliptic curve, so there will be no ECPoint. It is a random number as described here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.