企评社

Interface labels are shown in English. Company reviews, forum posts and tool descriptions are currently available in Chinese only.

Encoding converter

Base64, URL encoding, HTML entities, Unicode escapes, Hex and JWT decoding — six tabs, both directions in each

所有编解码都在你的浏览器里完成,不上传、不留存

六个标签页都只在你的浏览器里算:不提交表单、不请求接口、不写 localStorage 或网址参数。 Base64 与 JWT 里常常藏着密钥、token 或账号信息,编解码放在本地完成,是这页唯一的正确做法。

Base64 编解码

按 UTF-8 字节编码,所以中文与 emoji 都能正确往返。开「URL-safe」会把 + 换成 -、/ 换成 _(放进网址参数或文件名时用),开「去掉末尾的等号」会省略补位的 =。

文件 → Base64 / Data URL(文件不会离开你的设备)
把文件拖到这里,或点击选择文件
任意类型;只读字节并转成 Base64,不上传服务器

这几种「编码」到底在解决什么问题

Base64 不是加密,只是「换个字母表」。每 3 个字节切成 4 个 6 位再查表,于是二进制变成只含 A-Z、a-z、0-9、+、/ 与补位 = 的纯文本,长度涨约三分之一。谁都能一步还原,所以它只解决「二进制进不了文本协议」,不解决保密。变体两个:URL-safe 用 - 与 _ 代替 + 与 /;补位 = 可省,解码端按长度补回即可。

URL 编码为什么必须存在。网址里 ? & = # 有语法含义,参数值含这些字符就会被当结构解析——搜「A&B」时服务端会收到两个参数。所以值里的保留字符写成 %XX,非 ASCII 先按 UTF-8 变字节再转义。编码一个参数值用 encodeURIComponent(把 / ? & = 都编码掉,最安全),编码一整条网址才用 encodeURI(保留分隔符);表单口径的空格是 +,本页给了开关。

HTML 实体防的是注入。把用户内容直接拼进页面,一段含 script 的输入就会被执行(XSS);转义 &、<、>、" 与单引号即变回纯文本。其中 & 必须第一个替换,否则刚生成的 &lt; 会被再转一次成 &amp;lt;。解码要同时认十进制 &#20013; 与十六进制 &#x4E2D; 两种数字写法,以及命名实体。

Unicode 转义与代理对。JS 字符串以 UTF-16 为单位,\uXXXX 只能写到 FFFF;超出 BMP 的 emoji 占两个单位,所以 😀 的 4 位写法是 \uD83D\uDE00——两个转义合起来才是一个字符,只写 \uD83D 是半个字符;ES6 起可用码点写法 \u{1F600} 一次表示完。同理 '😀'.length 是 2 而不是 1。

Hex 与「字节」的关系。十六进制把每个字节写成两位,和 Base64 一样是编码不是加密,只是长两倍却更好核对。按 UTF-8 口径一个汉字占 3 字节,「中文」= e4b8ad e69687;同一个字按 GBK 是 d6d0,两边对不上时先确认编码口径,而不是怀疑工具。

JWT 三段结构与「解析不等于校验」。JWT 是三段 Base64URL:header 说算法与类型,payload 放声明(iss、sub、exp、iat、nbf 及业务字段),signature 是用密钥对前两段算出的签名。前两段只是编码,谁都能解开、也谁都能改,「解得开」和「没被改过」是两件事——真正的校验必须在服务端重算签名、防 alg 被改成 none、核对 iss 与 aud。

为什么这页坚持不上传。Base64 的原文常是密钥或证书、JWT 里一定带 token 与账号信息、URL 里常含回调地址与签名串。本页计算全是页面内的一段纯 JavaScript(写在源码的 PURE 区块里):打开 Network 面板除静态资源外没有任何请求,也不写 localStorage、不把内容放进网址参数,关掉页面即消失。

FAQ

Is Base64 encryption? Can I use it to protect passwords?

It is not encryption, just encoding: anyone holding a Base64 string can reverse it in one step, no key needed. Base64-ing a password or secret before storing it in a database or config file is equivalent to plaintext. For secrecy you need real encryption (such as AES-GCM) plus proper key custody; Base64 is for making binary data fit into text protocols - nothing more.

Why do some Base64 strings end with equals signs and others not? What is URL-safe?

Base64 encodes every 3 bytes into 4 characters; when the byte count is not a multiple of 3, = pads the tail - so equals signs appear only at the end, 0 to 2 of them. Many contexts (URL parameters, file names, JWT) drop the padding; decoders can restore it from the length - this page reads both forms. URL-safe means swapping + and / for - and _, because those two characters get escaped or mistaken for path separators inside URLs.

encodeURIComponent or encodeURI - which one?

For a parameter value use encodeURIComponent: it also encodes / ? & = so inserting it into a query string cannot break the structure. For a whole URL use encodeURI: it keeps the separators : / ? # & = - otherwise the URL collapses into a featureless blob. Also, the form encoding convention turns spaces into +, so when decoding strings from an http body you often need the 'treat + as space' option.

Why does an 😀 escape into two \u sequences instead of one?

Because JavaScript runs on UTF-16: \uXXXX covers only characters up to FFFF, and 😀 is U+1F600 - out of range, so it must be written as two UTF-16 units (a surrogate pair), \uD83D\uDE00. For a single escape per character use the code-point form \u{1F600}. This page lets you choose either form when encoding and reads both back into 😀.

My JWT decodes cleanly - does that mean the token is valid?

No. The header and payload are just JSON in Base64URL - anyone can decode them, and anyone can modify them. Decoding only proves the string looks like a JWT. Validity must be checked server-side: verify the signature with the key, and check the algorithm, issuer and expiry. This page parses without verifying - even the 'not expired' line on the page is no substitute for server-side signature verification.

Why are the times shown in GMT+8? Will it be wrong if my machine is in another zone?

exp / iat / nbf are Unix timestamps in UTC - absolute instants, independent of any display zone. The page displays them in China Standard Time GMT+8 for consistency with the site's other tools and domestic operations habits, using a fixed +8 offset, so your machine's timezone setting does not matter. The expired / not-yet-valid verdicts use your machine's current time as the reference and are informational only - the real verdict belongs to the server.

Related tools