How browsers word it
| Java | java.lang.IllegalArgumentException: Illegal base64 character 24 |
|---|---|
| Python 3 (validate=True) | binascii.Error: Only base64 data is allowed |
| Chrome and Node (atob) | InvalidCharacterError: The string to be decoded is not correctly encoded. |
Common causes
A stray symbol
A quote, a dollar sign, an asterisk or any other symbol is not part of the alphabet. Java reports its code in hex, so 24 is $ and 2a is *.
Input
SGVsbG8h$
Base64 says
Contains a character that is not Base64: "$"
A data: URL prefix
Browsers and APIs often hand you the whole data URL. Only the part after the comma is Base64.
Input
data:text/plain;base64,SGVsbG8=
Base64 says
Contains a character that is not Base64: ":"
A non-ASCII character
A letter such as é is never Base64. It usually means the text was altered on the way, for example by an editor or a mail client.
Input
SGVé
Base64 says
Contains a character that is not Base64: "é"
A space or a line break
Java's basic decoder and Python with validation refuse whitespace. This tool ignores it, so wrapped Base64 decodes.
Input
SGVs bG8=
Base64 says
Hello
The URL-safe alphabet
Tokens and URLs use - and _ in place of + and /. A standard decoder rejects them. This tool accepts both forms.
How to fix it
- Find the character the message names and remove it, or decode only the part after the comma of a data: URL.
- Take out spaces and line breaks, or use Java's getMimeDecoder, which skips them.
- For - and _, use the URL-safe decoder: Base64.getUrlDecoder in Java, urlsafe_b64decode in Python.
- Paste the text into the Base64 tool: it names the first character that does not belong.