📝 转换器

📐 使用说明与演算示例

演算示例 1:Base64 编码 输入文本:Hello
编码结果:SGVsbG8=
解码还原:Hello
Base64 将每 3 个字节编码为 4 个可打印字符。
演算示例 2:URL 编码 输入文本:你好 world
编码结果:%E4%BD%A0%E5%A5%BD%20world
解码还原:你好 world
URL 编码将空格和中文等字符转换为 %XX 格式。
演算示例 3:HTML 实体编码 输入文本:<script>alert(1)</script>
编码结果:&lt;script&gt;alert(1)&lt;/script&gt;
解码还原:<script>alert(1)</script>
HTML 实体编码可防止 XSS 攻击。

💡 Base64 编码有什么用?

Base64 将任意文本或二进制数据转换为 A-Z、a-z、0-9、+、/ 组成的字符串。常用于在 JSON 中传输图片、数据 URI 或邮件附件编码。本工具使用 JavaScript 内置的 btoaatob 实现,并已处理 Unicode 字符兼容问题。

💡 URL 编码和 HTML 实体编码有什么不同?

URL 编码将特殊字符(空格、中文、&、= 等)转换为 %XX 格式,确保网址能被正确解析。HTML 实体编码将 <、>、&、引号等字符转换为对应的实体名称,防止 XSS 攻击或页面显示错误。解码则还原为原始字符。

💡 为什么 Base64 编码中文会乱码?

JavaScript 原生的 btoa 函数不支持 Unicode 字符。本工具在底层先用 encodeURIComponent 将中文转为 UTF-8 字节序列,再进行 Base64 编码,确保中文字符可正常编解码。如果你在其他环境遇到乱码,请检查是否做了相同的 UTF-8 转换。

💡 这个工具完全离线运行吗?

是的。所有编码解码操作都在你的浏览器本地完成,输入的文本不会上传到任何服务器。即使断网也能正常使用。

📝 Converter

📐 Notes & Examples

Example 1: Base64 Encoding Input: Hello
Encoded: SGVsbG8=
Decoded: Hello
Base64 encodes every 3 bytes into 4 printable characters.
Example 2: URL Encoding Input: Hello world
Encoded: Hello%20world
Decoded: Hello world
Spaces become %20; Chinese characters become %XX sequences.
Example 3: HTML Entity Encoding Input: <script>alert(1)</script>
Encoded: &lt;script&gt;alert(1)&lt;/script&gt;
Decoded: <script>alert(1)</script>
HTML entities prevent XSS attacks by escaping dangerous characters.

💡 What is Base64 used for?

Base64 converts binary or text data into a string of A‑Z, a‑z, 0‑9, +, /. It's commonly used for data URIs, JSON image transmission, and email attachments. This tool uses JavaScript's btoa/atob with Unicode handling built in.

💡 Difference between URL encoding and HTML entities?

URL encoding replaces special characters with %XX format for safe transmission in URLs. HTML entity encoding replaces <, >, &, and quotes with their entity names to prevent XSS or rendering errors in HTML.

💡 Why do I get garbled text with Base64 and Chinese characters?

Native btoa doesn't support Unicode. This tool first converts the input to UTF‑8 bytes using encodeURIComponent before Base64 encoding, ensuring Chinese and other non‑ASCII characters work correctly.

💡 Does this tool work offline?

Yes. All encoding/decoding runs locally in your browser. No data is ever uploaded to any server, and it works even without an internet connection.