title: java.lang.IllegalArgumentException: bad base-64
body: <p>I am trying to encode and decode a String using android.util.Base64, but it gives a bad base-64 error. </p>
  
  <p>The code with the problem is:</p>
  
  <pre><code>private byte[] base64ToByte(String str) throws IOException {
  
      Log.i("encription", str);
      byte[] returnbyteArray = Base64.decode(str, Base64.URL_SAFE);
  
  
  
      return returnbyteArray;
  }
  </code></pre>
  
  <p>The error logcat is: </p>
  
  <pre><code>08-09 13:02:18.589: E/AndroidRuntime(29827): Process: com.example.maptest, PID: 29827
  08-09 13:02:18.589: E/AndroidRuntime(29827): java.lang.IllegalArgumentException: bad base-64
  08-09 13:02:18.589: E/AndroidRuntime(29827):    at android.util.Base64.decode(Base64.java:161)
  08-09 13:02:18.589: E/AndroidRuntime(29827):    at android.util.Base64.decode(Base64.java:136)
  08-09 13:02:18.589: E/AndroidRuntime(29827):    at android.util.Base64.decode(Base64.java:118)
  08-09 13:02:18.589: E/AndroidRuntime(29827):    at com.example.maptest.security.Encription.base64ToByte(Encription.java:116)
  08-09 13:02:18.589: E/AndroidRuntime(29827):    at com.example.maptest.security.Encription.encode(Encription.java:103)
  08-09 13:02:18.589: E/AndroidRuntime(29827):    at android.os.Handler.dispatchMessage(Handler.java:102)
  08-09 13:02:18.589: E/AndroidRuntime(29827):    at android.os.Looper.loop(Looper.java:136)
  08-09 13:02:18.589: E/AndroidRuntime(29827):    at android.app.ActivityThread.main(ActivityThread.java:5081)
  08-09 13:02:18.589: E/AndroidRuntime(29827):    at java.lang.reflect.Method.invokeNative(Native Method)
  08-09 13:02:18.589: E/AndroidRuntime(29827):    at java.lang.reflect.Method.invoke(Method.java:515)
  08-09 13:02:18.589: E/AndroidRuntime(29827):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
  08-09 13:02:18.589: E/AndroidRuntime(29827):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  08-09 13:02:18.589: E/AndroidRuntime(29827):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>The input(the str String from the code) looks like this: </p>
  
  <pre><code>08-09 13:02:18.539: I/encription(29827): 26.919047981500626
  </code></pre>
  
  <p>It is a double converted to a string, using:</p>
  
  <pre><code>String.valueOf(number)
  </code></pre>
  
  <p>The error is persistent with all encoding flags (DEFAULT, NO_WRAP, etc), any help would be apreciated, thank you.</p>