How browsers word it
| Chrome | InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded. |
|---|---|
| Node.js | InvalidCharacterError: Invalid character |
Common causes
The URL-safe alphabet
JWTs and many URLs use - and _ in place of + and /. atob() does not know them. The Base64 tool decodes both alphabets, with or without padding.
Input
-_8
Base64 says
Decoded: bytes FB FF
A data: URI prefix
A string such as data:image/png;base64,... carries a header before the data. Only the part after the comma is Base64.
Input
data:image/png;base64,iVBORw0KGgo=
Base64 says
Contains a character that is not Base64: ":"
Padding in the wrong place
= may only appear at the end, and at most twice. A stray = or any other symbol in the middle is invalid.
Input
SGVsbG8=!
Base64 says
Padding (=) is only allowed at the end
How to fix it
- Cut off any data: prefix and keep the text after the comma.
- Replace - with + and _ with / and add = padding to a multiple of 4, or decode with a tool that accepts Base64URL.
- Remove quotes, labels and other text that is not part of the Base64.
- Paste the string into the Base64 decoder: it says which character it does not accept.