× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Generating PublicKey from x and y values of elliptic curve point

Xaver Kapeller
May 14, 2015
<p>It's actually quite simple! But you need one more thing besides the <code>x</code> and <code>y</code> values. You also need an <code>ECParameterSpec</code>! The <code>ECParameterSpec</code> describes the elliptic curve you are using and your app has to use the same <code>ECParameterSpec</code> as your backend does!</p> <hr> <p>With the <code>x</code> and <code>y</code> values you can create an <code>ECPoint</code> instance and together with your <code>ECParameterSpec</code> you can create an <code>ECPublicKeySpec</code>:</p> <pre><code>ECParameterSpec ecParameters = ...; BigInteger x = ...; BigInteger y = ...; ECPoint ecPoint = new ECPoint(x, y); ECPublicKeySpec keySpec = new ECPublicKeySpec(ecPoint, ecParameters); </code></pre> <p>And now with that <code>ECPublicKeySpec</code> you can generate the <code>PublicKey</code> using a <code>KeyFactory</code>:</p> <pre><code>KeyFactory keyFactory = KeyFactory.getInstance("EC"); PublicKey publicKey = keyFactory.generatePublic(keySpec); </code></pre> <hr> <p>You can find more information about this topic <a href="http://www.bouncycastle.org/wiki/display/JA1/Elliptic+Curve+Key+Pair+Generation+and+Key+Factories" rel="nofollow"><strong>here</strong></a>.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/30116758/Generating%20PublicKey%20from%20x%20and%20y%20values%20of%20elliptic%20curve%20point/30184609">Stack Overflow</a>.</p>
comments powered by Disqus