问题描述
我一直在尝试将下面粘贴的代码转换为公钥。我正在尝试创建一个共享机密。我有密钥的未压缩十六进制表示形式。我想从中创建一个公钥。同样,我也希望创建私钥并在之后加入它们。
String plainPublicKey = "042E3E5CCF6B9AB04BE7A22F3FACCFDE73C87E87155394A34815408A896CA18A374DAC669AF3BF6220FC863767F4AF47507C5BC221FC4A19874DAF39B4074E3EB8";
EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(Hex.decodeHex(plainPublicKey.toCharArray()));
KeyFactory kf = KeyFactory.getInstance("EC");
PublicKey pub = kf.generatePublic(publicKeySpec);
return pub;
java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: invalid key format
at jdk.crypto.ec/sun.security.ec.ECKeyFactory.engineGeneratePublic(ECKeyFactory.java:157)
at java.base/java.security.KeyFactory.generatePublic(KeyFactory.java:352)
at AESExample.getPublicKey(AESExample.java:66)
at AESExample.main(AESExample.java:74)
Caused by: java.security.InvalidKeyException: invalid key format
at java.base/sun.security.x509.X509Key.decode(X509Key.java:386)
at java.base/sun.security.x509.X509Key.decode(X509Key.java:401)
at jdk.crypto.ec/sun.security.ec.ECPublicKeyImpl.<init>(ECPublicKeyImpl.java:71)
at jdk.crypto.ec/sun.security.ec.ECKeyFactory.implGeneratePublic(ECKeyFactory.java:219)
at jdk.crypto.ec/sun.security.ec.ECKeyFactory.engineGeneratePublic(ECKeyFactory.java:153)
... 3 more
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)