title: Java byte array to ECCPrivateKey - InvalidKeySpecException: encoded key spec not recognised
body: <p>When I try to make ECC private key from byte array, I get exception mentioned below. I have public/private keys and out signed output from C library micro-ecc/uECC.h. C used secp192r1 curve. I am trying to verify data with C generated keys in Java.  How to convert byte array to private/public key?</p>
  
  <pre><code>Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
  byte[] kb = new byte[]{(byte)0x24, (byte)0xF4, (byte)0x36, (byte)0x16, (byte)0xD0, (byte)0x96, (byte)0x12, (byte)0x63, (byte)0x90, (byte)0x2E, (byte)0x51, (byte)0xF6, (byte)0x87, (byte)0x55, (byte)0xAB, (byte)0xCB, (byte)0x5D, (byte)0xAC, (byte)0x56, (byte)0x1A, (byte)0xA5, (byte)0xFA, (byte)0x55, (byte)0xDB};
  X509EncodedKeySpec ks = new X509EncodedKeySpec(kb);
  KeyFactory kf = java.security.KeyFactory.getInstance("ECDH", "BC");
  org.bouncycastle.jce.interfaces.ECPrivateKey remotePublicKey = (org.bouncycastle.jce.interfaces.ECPrivateKey)kf.generatePublic(ks);
  
  java.security.spec.InvalidKeySpecException: encoded key spec not recognised
  at org.bouncycastle.jcajce.provider.asymmetric.util.BaseKeyFactorySpi.engineGeneratePublic(Unknown Source)
  at org.bouncycastle.jcajce.provider.asymmetric.ec.KeyFactorySpi.engineGeneratePublic(Unknown Source)
  at java.security.KeyFactory.generatePublic(KeyFactory.java:328)
  </code></pre>
  
  <p>Also I have tried to use </p>
  
  <pre><code>KeyFactory.getInstance("ECDH", "BC"); 
  </code></pre>
  
  <p>but it throws the same exception above.</p>
  
  <pre><code>KeyFactory.getInstance("EC");
  </code></pre>
  
  <p>throws</p>
  
  <pre><code>java.security.InvalidKeyException: invalid key format
  </code></pre>
  
  <p>or</p>
  
  <pre><code>java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException : DerInputStream.getLength(): lengthTag=116, too big.   
  </code></pre>