9

I'm getting a "java.lang.IllegalArgumentException: bad base-64" on the following code:

byte[] msgBytes = Base64.decode(msgStr, Base64.NO_WRAP);

msgString is a String, and right before this line, I check the value of msgStr and it is "fl-ILw==". Is there anything wrong?

Thanks.

user1118764
  • 9,255
  • 18
  • 61
  • 113

1 Answers1

10

According to RFC 4648(http://www.rfc-editor.org/rfc/rfc4648.txt) '-' character is not a valid Base64 character but on the other hand is valid for "URL and Filename safe Base 64 Alphabet".

So you could use Base64.URL_SAFE depending of the expected format of the string.

Izuel
  • 452
  • 6
  • 14
  • 1
    I see. Thanks. I did replace '/' and '+' to '_' and '-' respectively to keep it safe for naming files. That must be it then. Thanks! – user1118764 Apr 24 '14 at 01:32