跳至主要内容

UTF-8 Base64 与 URL 编解码器 (支持 Data URI)

UTF-8 安全的文本 Base64 编解码、完整 URL 参数转义与本地文件拖拽转 Data URI,完全在浏览器本地执行,零数据上传。

就绪,等待输入。

UTF-8 Base64 与 URL 工具

100% 本地运算

UTF-8 安全的文本 Base64 编解码、完整 URL 参数转义与本地文件拖拽转 Data URI,完全在浏览器本地执行,零数据上传。

0 字符

0 字符

UTF-8 Base64 & URL Encoding / Decoding Standards

Base64 encoding translates arbitrary binary data and text into an ASCII string format composed of 64 printable characters (A–Z, a–z, 0–9, +, /). It is the standard representation for embedding image assets into CSS/HTML via Data URIs, transmitting authorization headers, and serializing cryptographic signatures across network boundaries.

Why Traditional JavaScript btoa and atob Fail on Multilingual Text

The built-in browser APIs window.btoa and window.atob were specified for Latin-1 single-byte character sequences. Attempting to encode Unicode characters outside of the 0x00–0xFF range (such as Chinese, Japanese, Arabic, accented characters, or emojis) triggers an immediate InvalidCharacterError DOMException or creates corrupt garbage strings.

Our encoder uses the native TextEncoder and TextDecoder web APIs with fail-closed fatal diagnostics, ensuring true byte-level UTF-8 fidelity across all writing systems and complex multi-codepoint emojis (including zero-width joiner sequences).

Standard Base64 vs. URL-Safe Base64 (RFC 4648 § 5)

Standard Base64 uses the plus sign (+) and forward slash (/) characters. When placed in URL query strings or path segments, these characters conflict with URL syntax delimiters. URL-Safe Base64 substitutes hyphen (-) for + and underscore (_) for /, and omits trailing equal signs (=) so the payload can be transmitted in query strings or HTTP headers without double-encoding.

URL Component vs. Complete URL Encoding

  • URL Component Mode (encodeURIComponent): Encodes every reserved punctuation mark (such as ?, &, =, #, /, :) into percent-encoded hexadecimal triplets (e.g. %3F, %26, %3D). This is essential when embedding query parameter values that may themselves contain delimiters.
  • Complete URL Mode (encodeURI): Preserves standard protocol delimiters and query separators (https://, ?, &, =, #), encoding only invalid URL characters like spaces and Unicode codepoints.

RFC 2397 Data URI Scheme and Safe In-Browser File Decoding

The data: URI scheme allows small media assets (such as PNG icons, SVG vectors, or web fonts) to be embedded directly inline within HTML and CSS documents, eliminating additional HTTP round trips. Our tool preflights all files against memory guardrails (up to 20MB) to prevent browser tab crashes, inspects MIME media types and byte sizes, and safely decodes Data URIs back to downloadable byte-identical binary files with sanitized filenames.

Frequently Asked Questions

UTF-8 安全编码如何防止中文、日文和表情符号乱码?
原生 JavaScript 的 window.btoa 和 atob 仅支持 Latin-1 单字节范围,遇到汉字或复杂 Emoji 会直接抛出异常。我们通过原生的 TextEncoder 与 TextDecoder 严格以 UTF-8 字节流解码,确保任意语言和 Emoji 均可无损往返转换。
URL 参数组件模式与完整 URL 模式有什么区别?
参数组件模式(encodeURIComponent)会将问号、与号、等号等关键分隔符一并转义为百分号编码,以便安全作为请求参数传递;完整 URL 模式(encodeURI)则会保留 URL 骨架中的合法结构符号。
拖入的文件或敏感代码会被上传到服务器吗?
绝对不会。所有 Base64 编解码、文件转换为 Data URI 及反向导出下载均 100% 在您本机的浏览器内存中运行,绝无任何网络请求。