mzb86604
mzb86604

Reputation: 45

Bad Base64 input character decimal 208 in array position 0 (android)

Sorry for my english. I have method decode string, but in console i have warn. I get code string base64, and i need decode its string.

06-11 06:49:40.557: W/EGL_genymotion(1611): eglSurfaceAttrib not implemented
06-11 06:49:41.041: W/System.err(1611): java.io.IOException: Bad Base64 input character decimal 208 in array position 0
06-11 06:49:41.041: W/System.err(1611):     at com.motottaxi24user.Base64.decode(Base64.java:1201)
06-11 06:49:41.077: W/System.err(1611):     at com.motottaxi24user.Base64.decode(Base64.java:1122)
06-11 06:49:41.077: W/System.err(1611):     at com.motottaxi24user.User.decodeString(User.java:240)
06-11 06:49:41.097: W/System.err(1611):     at com.motottaxi24user.User$NewsAsynkTask.doInBackground(User.java:200)
06-11 06:49:41.137: W/System.err(1611):     at com.motottaxi24user.User$NewsAsynkTask.doInBackground(User.java:1)
06-11 06:49:41.141: W/System.err(1611):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-11 06:49:41.181: W/System.err(1611):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-11 06:49:41.197: W/System.err(1611):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-11 06:49:41.213: W/System.err(1611):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-11 06:49:41.217: W/System.err(1611):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-11 06:49:41.237: W/System.err(1611):     at java.lang.Thread.run(Thread.java:856)
06-11 06:49:41.281: W/System.err(1611): java.io.IOException: Bad Base64 input character decimal 58 in array position 2

Bellow my methods:

public String decodeString(String line) {
        byte[] tmp2;
        String val2 = null;

        try {
            tmp2 = Base64.decode(line);
            val2 = new String(tmp2, "UTF-8");
        } catch (IOException e) {
            e.printStackTrace();
        }

        return val2;
    }

Upvotes: 0

Views: 13168

Answers (2)

AterLux
AterLux

Reputation: 4654

The error message sais, that in your string at the second position is character with code 58. This is colon : that is not allowed in base64. So, check your input

Upvotes: 1

Gabriella Angelova
Gabriella Angelova

Reputation: 2985

Try with something like this:

public String decodeString(String line) {
  byte[] tmp2;
  String val2 = null;

  try {
      tmp2 = Base64.decode(line.getBytes());
      val2 = new String(Base64.encode(tmp2), "UTF-8");
  } catch (IOException e) {
      e.printStackTrace();
  }
  return val2;
}

Or take a look here Error when trying to encode/decode String to Base64

Upvotes: 0

Related Questions