title: RSA encryption causing IllegalBlockSizeException in Java
body: <p>After generating an AES key using:</p>
  <pre><code>keyGenerator = KeyGenerator.getInstance(&quot;AES&quot;);
  keyGenerator.init(256);
  keyGenerator.generateKey();
  </code></pre>
  <p>I'm concatenating this key with a 16 byte IV, then encoding</p>
  <pre><code>public String encode(byte[] content) {
      return Base64.encodeBase64String(content);
   }
  </code></pre>
  <p>I pass this string to an RSA cipher as follows</p>
  <pre><code>private final Cipher publicKeyCipher = Cipher.getInstance(&quot;RSA&quot;);
  publicKeyCipher.init(Cipher.ENCRYPT_MODE, publicKey);
  publicKeyCipher.doFinal(content.getBytes(StandardCharsets.UTF_8));
  </code></pre>
  <p>All this works fine as expected and tests work fine. But when load testing on a controlled environment the doFinal function throws</p>
  <pre><code>{&quot;log&quot;:&quot;javax.crypto.IllegalBlockSizeException: Data must not be longer than 245 bytes\n&quot;}
  </code></pre>
  <p>This occurs about 0-15% of 500,000 requests. Logs show string length and byte size are always fixed at 70 meaning under 245.
  So I don't think it's an encoding issue, I printed the string before encrypting it from one of the failed instances and tested it in a unit test which passed with no issues.</p>