Generating PublicKey from x and y values of elliptic curve point

ぐ巨炮叔叔 提交于 2019-11-30 19:18:33

It's actually quite simple! But you need one more thing besides the x and y values. You also need an ECParameterSpec! The ECParameterSpec describes the elliptic curve you are using and your app has to use the same ECParameterSpec as your backend does!


With the x and y values you can create an ECPoint instance and together with your ECParameterSpec you can create an ECPublicKeySpec:

ECParameterSpec ecParameters = ...;
BigInteger x = ...;
BigInteger y = ...;

ECPoint ecPoint = new ECPoint(x, y);
ECPublicKeySpec keySpec = new ECPublicKeySpec(ecPoint, ecParameters);

And now with that ECPublicKeySpec you can generate the PublicKey using a KeyFactory:

KeyFactory keyFactory = KeyFactory.getInstance("EC");
PublicKey publicKey = keyFactory.generatePublic(keySpec);

You can find more information about this topic here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!