>_ MoriDev dev.moritools.com
RFC 4648 · UTF-8 100% Client-Side · Zero Upload

Base64 & Base64URL Encoder / Decoder

Encode and decode UTF-8 text (including CJK and Emoji), switch between Base64 and Base64URL, or convert local files to Data URIs.

Ready (Offline)
Quick Summary

Convert arbitrary UTF-8 strings (including Chinese, Japanese, and multi-byte Emoji) into RFC 4648 Base64 or URL-safe Base64URL, or drop a local image/asset to generate an inline Data URI with zero upload.

Calling browser native btoa() directly on non-ASCII strings throws an InvalidCharacterError because btoa operates on Latin-1 code points rather than UTF-8 byte streams. Worse, mixing standard Base64 (+ and /) into OAuth state parameters or JWT segments breaks URL routing.

This encoder pipes text through TextEncoder/TextDecoder before applying RFC 4648 Section 4 (Standard) or Section 5 (Base64URL) alphabets, automatically strips whitespace or Data URI prefixes when decoding, and supports local drag-and-drop file encoding via FileReader/ArrayBuffer.

Common Base64 Implementation Traps

01. Using btoa() Directly on Unicode Strings

Passing "🚀" or "中文" directly to window.btoa throws DOMException. Encoding to UTF-8 bytes first ensures interoperability with Go encoding/base64, Python base64, and OpenSSL.

02. Treating Base64 as Encryption

Base64 adds zero confidentiality—it is a reversible 3-byte-to-4-character transport encoding that inflates binary size by ~33%. Never store passwords or API secrets in Base64 expecting secrecy.

03. Missing Padding (=) on Strict Backend Decoders

While Base64URL commonly omits trailing = characters, some Java, Python, and Go standard Base64 decoders reject unpadded strings unless length % 4 == 0. Our decoder auto-pads transparently while letting you control output padding.

Standard Base64 vs Base64URL Comparison

Property Standard Base64 (RFC 4648 §4) Base64URL (RFC 4648 §5)
Index 62 & 63 + and / characters - (hyphen) and _ (underscore)
Padding (=) Required to reach multiple of 4 Typically omitted in JWT/PKCE
URL & Filename Safe Requires percent-encoding (+ becomes space) Directly safe in query strings & paths
Size Overhead 4 output chars per 3 input bytes (+33.3%) Same 33.3% expansion (minus 0-2 =)

Worked Engineering Examples

Encoding Multi-Byte UTF-8 Emoji & CJK

Input
安全 🚀
Output
5a6J5YWoIPCfmoA= (Standard) / 5a6J5YWoIPCfmoA (Base64URL)

11 UTF-8 bytes encode cleanly into 16 Base64 characters without InvalidCharacterError.

Decoding a Data URI Payload

Input
data:text/plain;base64,SGVsbG8gTW9yaURldg==
Output
Hello MoriDev

The decoder automatically strips the data:*;base64, header before converting bytes back to UTF-8 text.

Frequently Asked Questions

Does dragging a local file here upload the file anywhere?

No. Files dropped into the dropzone are read into an in-memory ArrayBuffer inside your browser tab via File.arrayBuffer() and immediately converted to a Base64 Data URI.

When should I pick Base64URL over standard Base64?

Choose Base64URL for JWT segments, OAuth2 PKCE code challenges, signed cookies, URL query tokens, and filesystem-safe keys.

Why does my Base64 string grow by one-third?

Base64 packs 6 bits of binary data into each 8-bit ASCII character (2^6 = 64 symbols), creating an exact 4:3 byte expansion ratio plus up to two padding characters.

Can the decoder handle Base64 copied with line breaks from PEM or MIME?

Yes. All CR, LF, and whitespace characters are stripped before decoding, matching standard MIME and OpenSSL Base64 handling.

Continue Your Workflow

24 offline developer utilities