title: RSA encrypt with base64 encoded public key in Android
body: <p>How to do RSA encryption of byte array with base-64 encoded public key?</p>
  
  <p>After reading the couple of articles( of google search ) on how to do RSA encryption in Java, found the following snippet </p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>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.</p>