I know the curve name (secp256k1
) and the X
and Y
coordinates of the EC public key.
How do I make a org.bouncycastle.jce.int
A shorter variation on Thomas' answer, which does not use a KeyFactory
would be:
public static ECPublicKey decodeKey(byte[] encoded) {
ECNamedCurveParameterSpec params = ECNamedCurveTable.getParameterSpec("secp256k1");
ECPublicKeySpec keySpec = new ECPublicKeySpec(params.getCurve().decodePoint(encoded), params);
return new BCECPublicKey("ECDSA", keySpec, BouncyCastleProvider.CONFIGURATION);
}
I assume that encoded
was obtained by BCECPublicKey.getQ().getEncoded(bool)
, i.e. it is a byte 0x2-0x4
followed by one or two affine coordinates of the public point on secp256k1
.