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.
Presently the only way of "recovering" the Private key from the Public key is by exhaustive search (brute force). The system was specifically designed this way so that you could issue your public key to anyone without worrying about them being able to figure out your private key.
The private key always includes the public key. What you might really want is Signing. Using the same . NET classes, you can sign data with your private key and verify the signature on the other party's side with the public key (which obviously doesn't contain the private key).
PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(bytes));
For more info see this tutorial
For others who want to get private key instead of public key from byte array:
PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(privateKeyBytes));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With