Base64 encode and decode
Convert text to Base64 and back. Handles UTF-8 correctly, which the usual one-line browser trick does not, and nothing you paste leaves the page.
Runs in your browser — nothing is uploadedBase64 is not encryption
It is a way to carry bytes through a text-only channel. Anyone can decode it instantly. A
credential in Base64 is a credential in plain text with an extra step, and Authorization: Basic is
exactly that.
Base64 vs base64url
Standard Base64 uses + and /, both of which need escaping in a URL.
The URL-safe variant substitutes - and _ and usually drops the =
padding. JWTs use base64url, which is why pasting a JWT segment into a plain Base64 decoder often fails.
The UTF-8 trap
The browser's btoa() only handles characters below U+0100, so it throws on any
accented or non-Latin text. Text has to be encoded to UTF-8 bytes first. Anything that appears to work with
ASCII and breaks on the first accented character is hitting this.
Size
Base64 makes data roughly 33% larger. Inlining an image as a data URI trades a request for a third more bytes that cannot be cached separately.
Questions
Is Base64 encryption?
No. It is an encoding, fully reversible by anyone, with no key involved. It provides no confidentiality whatsoever.
What is the difference between Base64 and base64url?
base64url replaces + with - and / with _, and usually omits the = padding, so the result is safe in a URL or filename. JWT segments use it.
Why does btoa fail on my text?
btoa only accepts characters in the Latin-1 range. Non-ASCII text must be converted to UTF-8 bytes first. This tool does that for you.
How much bigger does Base64 make a file?
About 33%, since every three bytes become four characters, plus padding.