Bad base-64 error

I get "java.lang.IllegalArgumentException: bad base-64" in the following code:

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

msgString is a string, and right before that string I check the value of msgStr and this is "fl-ILw ==". Something is wrong?

Thanks.

+7
android base64 illegalargumentexception
source share
1 answer

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

So you can use Base64.URL_SAFE depending on the expected string format.

+6
source share

All Articles