title: Decoding and Encoding issue. Different implementations of Base64 Class in android.util.* and java.util.*?
body: <p>I am writing an App which does the following with a given String str: </p>
  
  <pre><code>encode(encrypt(encode(stringToBytearray(str))));
  </code></pre>
  
  <p>The Server receives the Base64 encoded String, which is then decoded -> decrypted -> decoded, to get the sent String str from the App.</p>
  
  <p>Unfortunately it doesnt work for all Strings, long Strings lead to a long Base64 String and my Server throws the following Exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: Illegal base64 character 5b
   at java.util.Base64$Decoder.decode0(Base64.java:714)
   at java.util.Base64$Decoder.decode(Base64.java:526)
   at Main.decode(Main.java:113)
   at Main.main(ain.java:33)
  </code></pre>
  
  <p>The String has the format "[string, string, ..., string]" without "s.</p>
  
  <p>Like I mentioned above, for Strings which are not too long (sorry I cant quantify the length yet), this works. So I think I implemented it right.</p>
  
  <p>Whats weird is, that if I dont send it, but decode(decrypt(decode(stringToBytearray(str)))); the String on the Device itself, it all works perfectly.</p>
  
  <p>My Setup:
  JDK 7, eclipse (adt-bundle, android development) (Windows 7)</p>
  
  <p>JDK 8, eclipse ('normal' java) (Linux (xubuntu))</p>
  
  <p>Is it because both Classes (Base64) are implemented diffrently? If so, how can I make it work?</p>
  
  <p>Here are the Encoding/Decoding Methods:</p>
  
  <p>Encoding (Device: on Windows 7, adt-bundle, Android-Dev, jdk 7):</p>
  
  <pre><code>import android.util.Base64
  
  public byte[] encode(byte[] bytearrayToEncode){
     return Base64.encode(bytearrayToEncode, Base64.NO_WRAP|Base64.URL_SAFE);
  }
  </code></pre>
  
  <p>Decoding (Server: on Linux, jdk 8):</p>
  
  <pre><code>import java.util.Base64
  
  public byte[] decode(byte[] bytearrayToEncode){
     return Base64.getUrlDecoder().decode(bytearrayToDecode);
  }
  </code></pre>
  
  <p>Strings are all De-/Encoded with the same charset (utf-8)!
  Encoding/Decoding: Base64</p>
  
  <p>Crypto: AES</p>
  
  <p>If you need more Information, just ask, but I think I provided all neccessary informations.</p>
  
  <p>Edit:</p>
  
  <pre><code>public String bytearrayToString(byte[] bytearray){
      String str = null;
      try {
          str = new String(bytearray, "UTF-8");
      } catch (UnsupportedEncodingException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      return str;
  }
  
  public byte[] stringToBytearray(String str){
      byte[] bytearray = null;
      try {
          bytearray = str.getBytes("UTF-8");
      } catch (UnsupportedEncodingException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      return bytearray;
  }
  </code></pre>