如何从byte []数组中恢复RSA公钥?

时间:2022-08-25 18:24:01

I'm wondering if it's possible to recover a RSA public key that I have converted to byte array previously.

我想知道是否有可能恢复我之前转换为字节数组的RSA公钥。

byte[] keyBytes = publicKey.getEncoded();

Thanks for the help.

谢谢您的帮助。

3 个解决方案

#1


83  

PublicKey publicKey = 
    KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(bytes));

For more info see this tutorial

有关详细信息,请参阅本教程

#2


30  

For others who want to get private key instead of public key from byte array:

对于其他想要从字节数组中获取私钥而不是公钥的人:

PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(privateKeyBytes));

#3


0  

Great answer. Thanks for the link. Just for complete, I found this Converted secret key into bytes, how to convert it back to secrect key?

很好的答案。谢谢你的链接。为了完整,我发现这个转换密钥为字节,如何将其转换回秘密密钥?

SecretKey key2 = new SecretKeySpec(data, 0, data.length, "DES");

and just worked very well.

并且工作得非常好。

#1


83  

PublicKey publicKey = 
    KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(bytes));

For more info see this tutorial

有关详细信息,请参阅本教程

#2


30  

For others who want to get private key instead of public key from byte array:

对于其他想要从字节数组中获取私钥而不是公钥的人:

PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(privateKeyBytes));

#3


0  

Great answer. Thanks for the link. Just for complete, I found this Converted secret key into bytes, how to convert it back to secrect key?

很好的答案。谢谢你的链接。为了完整,我发现这个转换密钥为字节,如何将其转换回秘密密钥?

SecretKey key2 = new SecretKeySpec(data, 0, data.length, "DES");

and just worked very well.

并且工作得非常好。