How to do RSA encryption of byte array with base-64 encoded public key?
After reading the couple of articles( of google search ) on how to do RSA encryption in Java, found the following snippet
public byte[] rsaEncrypt(byte[] data) {
PublicKey pubKey = readKeyFromFile("/public.key");
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, pubKey);
byte[] cipherData = cipher.doFinal(src);
return cipherData;
}
I have public key as a base64 encoded string (126 characters), How do i create 'PublicKey' with the encoded string and use it with Cipher.