Sunday, 25 August 2013

Genarate ECPublicKey in java

Genarate ECPublicKey in java

hi all 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 genarate Eccpublic
key.so i have created public key.but it gives
java.security.spec.InvalidKeySpecException: encoded key spec not
recognised error.This is my code anyone can help me how to generate
Eccpublickey using data array.Thanks
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();
}

No comments:

Post a Comment