title: ArrayIndexOutOfBoundsException : too much data for RSA block
body: <p>I have some problem with my android application. I am trying to an app related with RSA encryption/decryption.this is my problem:</p>
  
  <p>I can encrypt short sentences clearly, but when i try to decrypt this message to orginal text I give an error ("too much data for RSA block"). And also if I want to encrypt a long sentences i have same error.I had some search for this problem, and found some solution in this sites:</p>
  
  <p><a href="https://stackoverflow.com/questions/2579103/too-much-data-for-rsa-block-fail-what-is-pkcs7">Site 1</a></p>
  
  <p><a href="https://stackoverflow.com/questions/15806145/getting-error-java-lang-arrayindexoutofboundsexception-too-much-data-for-rsa-bl">Site 2</a></p>
  
  <p><a href="https://stackoverflow.com/questions/15024738/java-android-error-too-much-data-for-rsa-block">Site 3</a></p>
  
  <p>But i dont understand anything, these solutions are so complicated.How can i fixed this problem, Can anyone give me a more simple solution? Thank you.</p>
  
  <p>EDİT:
  These are the code blocks that i use for this project.</p>
  
  <pre><code>public String RSAEncrypt(String plain) throws NoSuchAlgorithmException, NoSuchPaddingException,InvalidKeyException, IllegalBlockSizeException, BadPaddingException, InvalidKeySpecException, UnsupportedEncodingException {
  
      publicKey = getPublicKey();
      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(Cipher.ENCRYPT_MODE, publicKey);
      byte[] cipherData = cipher.doFinal(plain.getBytes());
      return Base64.encodeToString(cipherData, Base64.DEFAULT);
  }
  
  public String RSADecrypt(byte[] encryptedBytes) throws NoSuchAlgorithmException, NoSuchPaddingException,InvalidKeyException, IllegalBlockSizeException, BadPaddingException, InvalidKeySpecException, UnsupportedEncodingException {
  
      privateKey = getPrivateKey();
      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(Cipher.DECRYPT_MODE, privateKey);      
      byte[] cipherData = cipher.doFinal(encryptedBytes);
      return Base64.encodeToString(cipherData, Base64.DEFAULT);
  }
  </code></pre>