Base64 Encoder / Decoder Base64 编解码


          

Base64 Encoding Explained

Base64 encodes binary data into 64 printable ASCII characters (A–Z, a–z, 0–9, +, /). Every 3 bytes of input maps to 4 characters, increasing data size by ~33%. It is the standard for Data URLs (data:image/png;base64,…), JWT token headers and payloads, HTTP Basic Auth headers, email attachments (MIME), and transmitting binary over text-only protocols. This tool uses TextEncoder / TextDecoder for full UTF-8 support — correctly handling Chinese, Japanese, emoji, and all Unicode.

Base64 vs Base64url

Standard Base64 uses + and / which are not URL-safe. Base64url substitutes them with - and _, and omits padding = signs. JWT tokens use Base64url. If you need URL-safe encoding, replace + with -, / with _, and strip trailing = from the output.

Base64 编码原理

Base64 将二进制数据编码为 64 个可打印 ASCII 字符(A–Z、a–z、0–9、+、/)。每 3 字节输入映射为 4 个字符,数据量增加约 33%。广泛用于 Data URL(data:image/png;base64,…)、JWT Token 的 Header 和 Payload、HTTP Basic Auth 头、电子邮件附件(MIME)等场景。本工具使用 TextEncoder / TextDecoder 实现完整 UTF-8 支持,可正确处理中文、日文、Emoji 等所有 Unicode 内容。

Base64 与 Base64url 的区别

标准 Base64 使用 + 和 /,这两个字符在 URL 中有特殊含义,不安全。Base64url 将其替换为 - 和 _,并省略末尾的 = 填充符。JWT Token 使用的是 Base64url 编码。如需 URL 安全编码,将输出中的 + 换成 -、/ 换成 _,去掉末尾 = 即可。