public static ECPublicKey decodeKey(byte[] encoded) throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchProviderException{
ECNamedCurveParameterSpec params = ECNamedCurveTable.getParameterSpec("secp256k1");
KeyFactory fact = KeyFactory.getInstance("ECDSA", "BC");
ECCurve curve = params.getCurve();
java.security.spec.EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, params.getSeed());
java.security.spec.ECPoint point=ECPointUtil.decodePoint(ellipticCurve, encoded);
java.security.spec.ECParameterSpec params2=EC5Util.convertSpec(ellipticCurve, params);
java.security.spec.ECPublicKeySpec keySpec = new java.security.spec.ECPublicKeySpec(point,params2);
return (ECPublicKey) fact.generatePublic(keySpec);
}
I'm implementation an android client at the moment and would be happy to chat re: any question you have.
Regards, etc.
Thank you #dirtyfilthy. I have been finding this for a while. Your solution is working. This piece of code is helping me injecting the generated public key from HSM into JCE. Somehow the sample on the boucny castle website is buggy. I hope this can help other ppl who needs importing the public key into JCE.
Cheers