How browsers word it
| Python 3 | binascii.Error: Incorrect padding |
|---|---|
| Java | IllegalArgumentException: Input byte array has incorrect ending byte at 7 |
Common causes
The padding was removed
Base64 in URLs and JWTs usually has no = signs. This tool accepts that and decodes the text, but Python and some other decoders do not.
Input
SGVsbG8
Base64 says
Hello
The text was cut off
A length that leaves one character over cannot be Base64, with or without padding. Part of the text is missing.
Input
SGVsb
Base64 says
The length is not valid for Base64 (one character too many or too few)
Too many equals signs
Padding is at most two = characters at the very end.
Input
SGVsbG8===
Base64 says
Too much padding. Base64 ends with at most two = characters
How to fix it
- Add = signs until the length is a multiple of four: in Python, text + "=" * (-len(text) % 4).
- Check that the text was not cut off by a log, a form field or a length limit.
- For the URL-safe alphabet (- and _), use urlsafe_b64decode, after adding the padding.
- Paste the text into the Base64 tool to see whether it decodes.