文本与 Base64 双向转换,中文和多语言按 UTF-8 处理,支持 URL 安全字符集与文件转码。 Convert text to Base64 and back, with UTF-8 handled properly, an optional URL-safe alphabet, and file encoding.
文件只在浏览器里读取,不会上传。建议 5 MB 以内——再大浏览器会明显卡。 The file is read locally and never uploaded. Keep it under about 5 MB; larger files visibly stall the browser.
Base64 是一种编码:把任意字节流映射成 64 个可打印字符,让二进制数据能塞进只能放文本的地方——邮件正文、JSON 字段、URL 参数、CSS 里的内嵌小图。它没有密钥,任何人都能还原,所以把密码「Base64 一下」并不安全,那只是穿了一件透明雨衣。真想保密要用加密(AES、ChaCha20 之类),Base64 解决的是「能不能传输」,不是「别人能不能看」。 Base64 is an encoding: it maps an arbitrary byte stream onto 64 printable characters so binary data can travel where only text fits — email bodies, JSON fields, URL parameters, small images inlined in CSS. There is no key; anyone can reverse it. “Base64-ing” a password does not secure it — that's a transparent raincoat. Confidentiality needs actual encryption (AES, ChaCha20 and friends). Base64 answers “can I transmit this”, not “can others read it”.
Base64 编码的是字节,不是字符。一个汉字在 UTF-8 里占 3 个字节,在 GBK 里占 2 个。如果编码端按 UTF-8 编,解码端却按 GBK 或 Latin-1 解,出来的就是「锟斤拷」或一串问号。本工具两头都固定用 UTF-8:编码前用 TextEncoder 把字符串转成 UTF-8 字节,解码后用 TextDecoder 按 UTF-8 还原。碰到别人的工具产生的乱码,通常是它用了旧的 btoa()——那个函数只接受 Latin-1,遇到中文会直接抛异常或悄悄截断。
Base64 encodes bytes, not characters. One Chinese character is three bytes in UTF-8 and two in GBK. If the encoder assumes UTF-8 and the decoder assumes GBK or Latin-1, you get mojibake or a row of question marks. This tool pins both ends to UTF-8: TextEncoder turns the string into UTF-8 bytes before encoding, and TextDecoder restores it after decoding. When another tool produces garbage, it usually used the old btoa(), which only accepts Latin-1 and throws or silently truncates on Chinese input.
标准 Base64 的字符表里有 + 和 /,还有补位的 =。放进 URL 或文件名时,+ 会被解码成空格,/ 会被当成路径分隔符,= 有时惹麻烦。所以有 base64url:把 + 换成 -、/ 换成 _、去掉末尾的 =。JWT(JSON Web Token)用的就是这一套——你看它三段用点号隔开,前两段正是 base64url 编码的 JSON。把 token 前两段分别粘进解码区,就能看到头部和载荷,注意载荷只是编码过,任何人拿到 token 都能读。
Standard Base64's alphabet includes + and /, plus = padding. In URLs and filenames, + decodes to a space, / acts as a path separator, and = sometimes causes trouble. Hence base64url: + becomes -, / becomes _, trailing = is dropped. JWTs use exactly this — the three dot-separated segments begin with two base64url-encoded JSON objects. Paste the first two into the decoder to read header and payload; remember the payload is merely encoded, so anyone holding the token can read it.
Base64 每 3 个字节变成 4 个字符,体积固定膨胀约 33%。一张 100 KB 的图内联进 HTML 会变成约 137 KB 的文本,而且无法被浏览器单独缓存——所以小图标内联划算,大图内联往往更慢。判断标准通常是 10 KB 上下。 Base64 turns every 3 bytes into 4 characters — a fixed ~33% expansion. A 100 KB image inlined into HTML becomes about 137 KB of text and cannot be cached separately, so inlining tiny icons pays off while inlining large images usually makes pages slower. Ten kilobytes is a common dividing line.
先检查有没有混进空格、换行或中文标点(本工具会自动忽略空白,但不认全角符号);再检查是否缺了末尾的 = 补位——本工具会自动补齐,但如果长度模 4 余 1,那就不是 Base64。还有一种情况:数据其实是压缩过的(gzip/deflate),得先解压。
First check for spaces, newlines or full-width punctuation (whitespace is ignored here, full-width symbols are not); then check for missing trailing = — padding is restored automatically, but a length of 1 mod 4 is not Base64 at all. Another case: the data is compressed (gzip/deflate) and must be decompressed first.
说明原始字节不是 UTF-8 文本——可能是图片、压缩包、加密数据,或者是 GBK 编码的老文本。用「下载为 .bin」存下来,再用 file 命令或对应工具打开判断真实格式。
The bytes aren't UTF-8 text — probably an image, an archive, encrypted data, or an old GBK document. Save it with “Download as .bin”, then run file or open it with the right tool to identify the real format.
不行。Base64 只是换了个写法的原文,谁拿到都能还原。密码要用加盐慢哈希(bcrypt、scrypt、Argon2),密钥要用加密或密钥管理服务保存。把密钥 Base64 一下再提交到仓库,等于明文提交。 No. Base64 is the same plaintext in a different outfit, reversible by anyone. Passwords need a salted slow hash (bcrypt, scrypt, Argon2); keys need encryption or a key-management service. Base64-ing a key before committing it is committing it in the clear.