title: Generate ECPublicKey in java
body: <p>I am new to java ecc encryption. So I got ECC public key data array from java card.the size is 49 byte length. So I need to generate Eccpublic key. So I have created public key. but it gives error:</p>
  
  <blockquote>
    <p>java.security.spec.InvalidKeySpecException: encoded key spec not recognised</p>
  </blockquote>
  
  <p>This is my code. How to generate Eccpublickey using data array?</p>
  
  <pre><code>byte[] pub = new byte[] {
      /*(Public data) 49 length byte ARRAY
      */
  
  
       };
  
      System.out.println("Length :" + pub.length);
      X509EncodedKeySpec ks = new X509EncodedKeySpec(pub);
  
      KeyFactory kf;
      try {
          kf = KeyFactory.getInstance("ECDH");
  
      } catch (NoSuchAlgorithmException e) {
          e.printStackTrace();
          return;
      }
  
      ECPublicKey remotePublicKey;
  
      try {
          remotePublicKey = (ECPublicKey) kf.generatePublic(ks);
      } catch (InvalidKeySpecException e) {
          e.printStackTrace();
          return;
      } catch (ClassCastException e) {
          e.printStackTrace();
          return;
      }
      System.out.println(remotePublicKey);
  
  } catch (Exception e) {
      e.printStackTrace();
  }
  </code></pre>