Base64 编解码 使用教程
详细使用指南、最佳实践与常见问题解答
使用场景
Base64 编解码工具适用于处理 Data URL、邮件附件、JWT Token、API 数据传输、嵌入图片到 HTML/CSS 等场景。当你需要将二进制数据或特殊字符转为 ASCII 安全格式,或将 Base64 还原为原始内容时,这个工具能快速完成转换。
Use Cases
The Base64 encoder/decoder is useful for handling Data URLs, email attachments, JWT tokens, API data transmission, and embedding images in HTML/CSS. Use it to convert binary data or special characters to ASCII-safe format, or to restore Base64 to its original content.
功能特点
- 双向转换:编码和解码一键切换
- UTF-8 安全:正确处理中文、emoji 等多字节字符
- 实时输出:输入即转换,无需点击按钮
- 错误提示:无效 Base64 会显示明确错误
- 一键复制:结果可快速复制到剪贴板
Features
- Bidirectional: encode and decode with one toggle
- UTF-8 safe: correctly handles Chinese, emoji, and other multi-byte characters
- Real-time output: converts as you type, no button clicks needed
- Error messages: invalid Base64 shows clear error messages
- One-click copy: results can be quickly copied to clipboard
使用示例
示例 1:场景一:将图片转为 Base64 编码嵌入 HTML,减少 HTTP 请求:`<img src="data:image/png;base64,...">`。
示例 2:场景二:解码 JWT Token 的 Payload 部分,查看用户信息和过期时间。
示例 3:场景三:将中文用户名编码后通过只支持 ASCII 的 API 传输,到达后再解码还原。
Examples
Example 1: Scenario 1: Convert an image to Base64 and embed it in HTML to reduce HTTP requests: `<img src="data:image/png;base64,...">`.
Example 2: Scenario 2: Decode the Payload part of a JWT token to view user info and expiration time.
Example 3: Scenario 3: Encode a Chinese username for transmission via ASCII-only APIs, then decode at the destination.
最佳实践
- Base64 不是加密,任何人都能解码,不要用于存储敏感数据
- Base64 编码后体积增加约 33%,不适合大文件
- 处理中文时确保使用 UTF-8 编码,避免乱码
- Data URL 嵌入图片建议小于 10KB,否则反而影响性能
Best Practices
- Base64 is not encryption — anyone can decode it. Do not use it to store sensitive data
- Base64 increases size by about 33%, so it is not suitable for large files
- When handling Chinese text, ensure UTF-8 encoding to avoid garbled characters
- For Data URL embedded images, keep them under 10KB or performance may suffer
常见问题
Base64 是加密吗?安全吗?
不是。Base64 只是编码方式,任何人都能解码,不具备任何加密安全性。不要用 Base64 存储密码或敏感数据。
为什么解码后中文是乱码?
通常是因为原编码使用了非 UTF-8 字符集(如 GBK)。本工具默认使用 UTF-8,确保编码时也用 UTF-8 即可正确解码。
支持 Base64URL 变体吗?
当前版本仅支持标准 Base64(含 + / = 字符)。Base64URL(- _ 替代)暂不支持,建议用 JWT 解码器处理 Token。
FAQ
Is Base64 encryption? Is it secure?
No. Base64 is just an encoding scheme — anyone can decode it. It provides no encryption security. Do not use it to store passwords or sensitive data.
Why is Chinese text garbled after decoding?
Usually because the original encoding used a non-UTF-8 charset (like GBK). This tool uses UTF-8 by default — ensure the encoding step also uses UTF-8.
Does it support the Base64URL variant?
The current version only supports standard Base64 (with + / = characters). Base64URL (using - _) is not supported — use the JWT Decoder for tokens.