🔤 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 |
📌 说明
- 编码:将任意文本转换为 Base64 字符串。
- 解码:将 Base64 字符串还原为原始文本,失败会提示错误。
- Base64Url 将 + 替换为 -,/ 替换为 _,并去除末尾 =。