Base64 URL-safe Encoder|Base64 URL 安全编码

Base64 URL-safe Encoder | Base64 URL 安全编码

Base64 URL-safe Encoder Base64 URL 安全编码

将任意文本编码为 base64url(URL-safe Base64)字符串:把 +// 替换为 /_,并可选移除 = 填充。
Encode text into base64url (URL-safe Base64): replace +// with /_, and optionally remove = padding.

1. 输入参数 · Input
编码:输入普通文本,生成 base64url 字符串。
Encode: input plain text and get base64url string.
解码:输入 base64url(或普通 Base64),还原为文本(UTF-8)。
Decode: input base64url (or standard Base64) and restore text (UTF-8).
提示:base64url 常用于 URL 参数、JWT(header/payload)、短 token 传递等场景。
Tip: base64url is common in URL parameters, JWT (header/payload), and compact token transport.
快捷键:Ctrl + Enter 立即执行。
Shortcut: Ctrl + Enter to run instantly.
移除 padding:JWT 常见做法,字符串更短,但解码时需要自动补齐。
Remove padding: common in JWT, shorter output; decoder will auto-pad when needed.
encodeURIComponent:仅在你要把结果直接拼接到 URL 时才考虑;通常 base64url 已足够安全。
Use encodeURIComponent only when you directly concatenate into a URL; base64url is usually safe enough.
保留换行:默认会把换行按文本编码进结果;勾选只是避免“自动清理换行”。
Keep newlines: newlines are encoded as text bytes; this option prevents auto-cleaning.
3. 使用说明 · Notes
  • 什么是 Base64URL? · What is Base64URL?
    Base64URL(也叫 base64url / URL-safe Base64)是对普通 Base64 的“URL 场景适配”:把 + 替换为 ,把 / 替换为 _,并且经常把末尾的 = padding 去掉,让字符串更短、更适合放到 URL 或 token 里。
    Base64URL (base64url / URL-safe Base64) adapts standard Base64 for URLs: it replaces +, /_, and often removes trailing = padding to make it shorter and URL-friendly.
  • Base64URL ≠ URL 编码 · Base64URL is NOT percent-encoding
    Base64URL 解决的是“Base64 字符集中不适合 URL 的字符”,而不是替代 encodeURIComponent。大多数情况下,把 base64url 放在 query 参数里是可行的;但如果你的系统会再次进行特殊解析(例如某些网关/框架对 ._ 有额外规则,或你要拼接到路径段中),你可以勾选“额外做 URL 编码”。
    Base64URL fixes unsafe characters in Base64; it doesn’t replace encodeURIComponent. Usually base64url is safe in query parameters, but if your pipeline has special parsing rules or you embed it into path segments, applying percent-encoding can be a safer choice.
  • 关于 padding(=) · About padding (=)
    普通 Base64 会用 = 补齐长度到 4 的倍数;base64url 在 JWT 等场景里经常移除 padding。移除后并不影响信息本身,但解码时需要根据长度自动补齐:长度对 4 取模为 2 → 补 ==;为 3 → 补 =;为 0 → 不用补。
    Standard Base64 uses = padding to make length a multiple of 4. In JWT, padding is often omitted. It doesn’t change the data, but decoders must auto-pad based on length: mod 4 = 2 → add ==; mod 4 = 3 → add =; mod 4 = 0 → add nothing.
  • 典型应用场景 · Typical use cases
    1)JWT 的 header / payload(它们就是 base64url);2)把短二进制/文本数据放进 URL 参数;3)对称/非对称签名流程中的“可传输文本”中间态;4)在日志里安全展示小段数据(避免不可见字符)。
    1) JWT header/payload (they are base64url); 2) carrying small binary/text data in URL parameters; 3) a transport-friendly intermediate string in signing flows; 4) safely displaying small data in logs (avoids invisible bytes).
  • 安全提醒 · Security reminder
    Base64 / base64url 只是编码(encoding),不是加密(encryption),也不是哈希(hash)。它不会“隐藏”内容,只是换一种可传输的表示方式。敏感数据不要因为做了 base64url 就当成安全。
    Base64/base64url is encoding, not encryption or hashing. It does not hide content—only changes representation. Don’t treat base64url as security for sensitive data.
  • 本工具隐私说明 · Privacy
    本页面全部逻辑在浏览器本地运行,不上传、不联网。适合做接口调试、文档示例、token 结构演示。
    Everything runs locally in your browser—no upload, no network calls. Good for API testing, docs examples, and token demos.

备注:不同语言/框架对 Base64 的实现细节可能不同(尤其是 UTF-8 与二进制处理)。本工具使用 UTF-8 对文本进行编码与解码,并对 base64url 的 padding 做了兼容处理。
Note: Base64 implementations may vary across languages/frameworks (especially UTF-8 vs binary handling). This tool encodes/decodes text as UTF-8 and normalizes padding for base64url.