I have the x and y coordinate of a point and the name of a curve. I now want to create an org.bouncycastle.jce.interfaces.ECPublicKey
object from that, automatically using the implementation that is provided. The goal is to be able to create the objects no matter if bouncycastle or its Android port, spongycastle, is used.
我有一个点的x和y坐标以及一个曲线的名称。我现在想要从中创建一个org.bouncycastle.jce.interfaces.ECPublicKey对象,自动使用提供的实现。无论是否使用bouncycastle或其Android端口spongycastle,目标都是能够创建对象。
This is what I'm doing right now. Thing is, the EC5Util class is not included in spongycastle. I'd like to have a solution using maybe a factory with just one method I have to call. Is that possible?
这就是我现在正在做的事情。事实上,EC5Util类不包含在spongycastle中。我希望有一个解决方案,可能只使用一种工厂,我只需要调用一种方法。那可能吗?
java.security.spec.ECPoint w = new java.security.spec.ECPoint(x, y);
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.ECParameterSpec params2 = EC5Util.convertSpec(ellipticCurve, params);
java.security.spec.ECPublicKeySpec keySpec = new java.security.spec.ECPublicKeySpec(w, params2);
return (ECPublicKey) fact.generatePublic(keySpec);
1 个解决方案
#1
1
The unit tests within Bouncycastle, in ECPointTest.java, appears to have coverage for this case:
Bouncycastle中的单元测试,在ECPointTest.java中,似乎涵盖了这种情况:
ECFieldElement.Fp x_ecfe = new ECFieldElement.Fp(q, x);
ECFieldElement.Fp y_ecfe = new ECFieldElement.Fp(q, y);
ECPoint.Fp point = new ECPoint.Fp(curve, x_ecfe, y_ecfe);
This is a very unique situation you are in. If you cared to expand why you are doing this I'd be interested to find out.
这是一个非常独特的情况。如果你关心扩展你为什么这样做,我有兴趣找出来。
#1
1
The unit tests within Bouncycastle, in ECPointTest.java, appears to have coverage for this case:
Bouncycastle中的单元测试,在ECPointTest.java中,似乎涵盖了这种情况:
ECFieldElement.Fp x_ecfe = new ECFieldElement.Fp(q, x);
ECFieldElement.Fp y_ecfe = new ECFieldElement.Fp(q, y);
ECPoint.Fp point = new ECPoint.Fp(curve, x_ecfe, y_ecfe);
This is a very unique situation you are in. If you cared to expand why you are doing this I'd be interested to find out.
这是一个非常独特的情况。如果你关心扩展你为什么这样做,我有兴趣找出来。