我是 java ecc 加密的新手。所以我从 java 卡中得到了 ECC 公钥数据数组。大小为 49 字节长度。所以我需要生成 Eccpublic 密钥。所以我创建了公钥。但它给出了错误:
java.security.spec.InvalidKeySpecException:编码的密钥规范无法识别
这是我的代码。如何使用数据数组生成 Eccpublickey?
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();
}