🔤 Base64 Encode / Decode

Encode and decode Base64 online

📐 工作原理與說明
Base64 把每 3 位元組(24 位)重分為 4 個 6 位組,每組對映到 64 字元表(A 至 Z、a 至 z、0 至 9、加號、斜槓);不足 3 位元組時補零並以等號填充(缺 1 位元組補 2 個等號、缺 2 位元組補 1 個等號);編碼後長度 = 原長度 ÷ 3 向上取整 × 4;Base64Url 以短橫代替加號、下劃線代替斜槓並省略填充,Unicode 文本須先按 UTF-8 轉位元組再編碼。

Formula & Standard References

Item Formula / Rule Source / Standard
Encoding order Characters are first encoded as UTF-8 bytes, then the byte string is Base64 encoded RFC 4648 §4 / RFC 3629 UTF-8
Length difference Characters and bytes diverge: one CJK character becomes 3 bytes and then 4 Base64 characters RFC 4648 §4, 6-bit group mapping
Padding handling Decoding skips whitespace other than "=", and missing padding can be inferred from length RFC 4648 §3.3 and §3.5 Canonical Encoding
📌 說明