I am new to Cryptography. I was provided with a RSA public key in base64 format. Is there any way to encrypt some text using just the public key. Do I need modulus/exponent too?
Any pointers would be very helpful. Thanks
I am new to Cryptography. I was provided with a RSA public key in base64 format. Is there any way to encrypt some text using just the public key. Do I need modulus/exponent too?
Any pointers would be very helpful. Thanks
I was interested as well, I went "Google-ing" and found this interesting page. It is a lot of information, but very interesting in my opinion.
Saying it is in base64 format is not enough information. There are at least two common ways that an RSA public key may be formatted, and either one may be base64 encoded. If you are lucky, the key is an X509EncodedKeySpec. If so, you need to base64 decode it, create a KeyFactory
, then use the KeyFactory to generate the public key. Here some untested, not even compiled, code that hopefully shows these steps.
// Example using the base64 class from http://iharder.sourceforge.net/current/java/base64/
byte [] x509Key = Base64.decode(base64Key);
KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPublicKey rsaPub = (RSAPublicKey) kf.generatePublic();
If there are -----BEGIN and ----END lines surrounding your base64 key just delete them.
The public key is used to decrypt ciphertext which has been encrypted by the private key.
Each user that want to communicate has a pair of cryptographic keys—a public encryption key and a private decryption key.
You can encrypt using the public key becuse the keys are derived mathematically, but parameters are chosen so that determining the private key from the public key is prohibitively expensive.