Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad base-64 error

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.

like image 764
user1118764 Avatar asked Apr 23 '14 10:04

user1118764


People also ask

What is meant by base 64?

Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.

Is base 64 URL safe?

By consisting only of ASCII characters, base64 strings are generally url-safe, and that's why they can be used to encode data in Data URLs.

Can base 64 be decoded?

Base64 Decode is very unique tool to decode base64 data to plain text. This tool saves your time and helps to decode base64 data. This tool allows loading the Base64 data URL, which loads base64 encoded text and decodes to human readable text.

What is a base 64 image?

Base64 images are primarily used to embed image data within other formats like HTML, CSS, or JSON. By including image data within an HTML document, the browser doesn't need to make an additional web request to fetch the file, since the image is already embedded in the HTML document.


1 Answers

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.

like image 128
Izuel Avatar answered Sep 22 '22 11:09

Izuel