title: java.lang.IllegalArgumentException: bad base-64 when decrypting string
body: <p>I am trying to encrypt a string using the KeyStore and used this post as reference.</p>
  
  <p><a href="https://stackoverflow.com/questions/36802523/keypairgeneratorspec-replacement-with-keygenparameterspec-builder-equivalents">KeyPairGeneratorSpec replacement with KeyGenParameterSpec.Builder equivalents - Keystore operation failed</a></p>
  
  <p>yet, I keep getting this "bad base-64" when I decrypt the string. I am not understanding exactly how to fix this. I understand that the encrypted string contains characters that the decryptor does not know. But I don't understand the fix.</p>
  
  <p>I saw some posts like those, but did not help much since there is no code on the answers.</p>
  
  <p><a href="https://stackoverflow.com/questions/25217515/java-lang-illegalargumentexception-bad-base-64">java.lang.IllegalArgumentException: bad base-64</a></p>
  
  <p>This is a snipped of my the test code, can someone show me how I decrpyt my string?</p>
  
  <pre><code>Cipher inCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", "AndroidOpenSSL");
  inCipher.init(Cipher.ENCRYPT_MODE, publicKey);
  
  Cipher outCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", "AndroidOpenSSL");
  outCipher.init(Cipher.DECRYPT_MODE, privateKey);
  
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  CipherOutputStream cipherOutputStream = new CipherOutputStream(
          outputStream, inCipher);
  cipherOutputStream.write(plainText.getBytes("UTF-8"));
  cipherOutputStream.close();
  
  String ecryptedText = outputStream.toString();
  Log.d(TAG, "Encrypt = " + ecryptedText);
  
  String cipherText = ecryptedText;
  CipherInputStream cipherInputStream = new CipherInputStream(
          new ByteArrayInputStream(Base64.decode(cipherText, Base64.DEFAULT)), outCipher);
  ArrayList&lt;Byte&gt; values = new ArrayList&lt;&gt;();
  int nextByte;
  while ((nextByte = cipherInputStream.read()) != -1) {
      values.add((byte)nextByte);
  }
  
  byte[] bytes = new byte[values.size()];
  for(int i = 0; i &lt; bytes.length; i++) {
      bytes[i] = values.get(i).byteValue();
  }
  
  String finalText = new String(bytes, 0, bytes.length, "UTF-8");
  Log.d(TAG, "Decrypt = " + ecryptedText);
  </code></pre>