How to recover a RSA public key from a byte[] array?

kiewic picture kiewic · Mar 9, 2010 · Viewed 46.7k times · Source

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

byte[] keyBytes = publicKey.getEncoded();

Thanks for the help.

Answer

Bozho picture Bozho · Mar 9, 2010
PublicKey publicKey = 
    KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(bytes));

For more info see this tutorial