Base64 / URL / HTML Encoder & Decoder
Encode or decode text using Base64, URL percent-encoding, or HTML entities. Processes text client-side with no external calls.
Input
- - The text string to encode or decode
- Encoding type:
base64 (default), url, or INLINECODE2 - Direction:
encode (default) or INLINECODE4
Output
- - The transformed string
- A brief note on the encoding type and direction applied
Instructions
Base64 (type: base64)
Encode:
- 1. Take the input string.
- Convert each character to its UTF-8 byte sequence (handle non-ASCII/Unicode correctly).
- Apply Base64 encoding using the standard alphabet (A–Z, a–z, 0–9, +, /).
- Pad with
= characters to make the length a multiple of 4. - The algorithm equivalent is:
btoa(unescape(encodeURIComponent(input))).
Decode:
- 1. Take the Base64-encoded input.
- Validate it contains only valid Base64 characters (A–Z, a–z, 0–9, +, /, =).
- Decode using:
decodeURIComponent(escape(atob(input))). - Return the original UTF-8 string.
URL Percent-Encoding (type: url)
Encode:
- 1. Apply
encodeURIComponent semantics: encode every character except A–Z a–z 0–9 - _ . ! ~ * ' ( ). - Spaces become
%20 (not +). - Non-ASCII characters are UTF-8 encoded then percent-escaped.
Decode:
- 1. Replace each
%XX sequence with the corresponding byte. - Interpret the resulting bytes as UTF-8.
- Equivalent to
decodeURIComponent(input).
HTML Entities (type: html)
Encode: Replace these characters with their named HTML entities:
- -
< → INLINECODE15 - INLINECODE16 → INLINECODE17
- INLINECODE18 → INLINECODE19
- INLINECODE20 → INLINECODE21
- INLINECODE22 → INLINECODE23
Decode: Reverse the mapping — replace each HTML entity with its literal character.
Options
- -
type: base64 | url | html — default: INLINECODE28 - INLINECODE29 :
encode | decode — default: INLINECODE32
Examples
Base64 encode:
Input: Hello, World!
Output: INLINECODE34
Base64 encode (Unicode):
Input: Héllo
Output: INLINECODE36
Base64 decode:
Input: SGVsbG8sIFdvcmxkIQ==
Output: INLINECODE38
URL encode:
Input: name=John Doe&city=New York
Output: INLINECODE40
URL decode:
Input: hello%20world%21
Output: INLINECODE42
HTML encode:
Input: <script>alert("XSS")</script>
Output: INLINECODE44
HTML decode:
Input: <h1>Hello & welcome</h1>
Output: INLINECODE46
Error Handling
- - Invalid Base64 input for decode: If the string contains characters outside the Base64 alphabet or has incorrect padding, report:
Error: Invalid Base64 string. Ask the user to verify the input. - Invalid URL encoding for decode: If a
%XX sequence uses non-hex digits or the sequence is incomplete, report: Error: Invalid URL encoded string. - Empty input: Return an empty string with a note that no input was provided.
- Binary/non-text data: Warn the user that Base64 encoding of binary data requires the raw bytes, which cannot be provided as plain text — suggest they use a tool that accepts file uploads.
Base64 / URL / HTML 编码与解码器
使用 Base64、URL 百分比编码或 HTML 实体对文本进行编码或解码。所有处理均在客户端完成,无需外部调用。
输入
- - 待编码或解码的文本字符串
- 编码类型:base64(默认)、url 或 html
- 方向:encode(编码,默认)或 decode(解码)
输出
- - 转换后的字符串
- 关于所应用的编码类型和方向的简要说明
操作说明
Base64(类型:base64)
编码:
- 1. 获取输入字符串。
- 将每个字符转换为其 UTF-8 字节序列(正确处理非 ASCII/Unicode 字符)。
- 使用标准字母表(A–Z、a–z、0–9、+、/)应用 Base64 编码。
- 使用 = 字符进行填充,使长度成为 4 的倍数。
- 等效算法为:btoa(unescape(encodeURIComponent(input)))。
解码:
- 1. 获取 Base64 编码的输入。
- 验证其仅包含有效的 Base64 字符(A–Z、a–z、0–9、+、/、=)。
- 使用以下方法解码:decodeURIComponent(escape(atob(input)))。
- 返回原始的 UTF-8 字符串。
URL 百分比编码(类型:url)
编码:
- 1. 应用 encodeURIComponent 语义:对除 A–Z a–z 0–9 - _ . ! ~ * ( ) 之外的所有字符进行编码。
- 空格变为 %20(而非 +)。
- 非 ASCII 字符先进行 UTF-8 编码,然后进行百分比转义。
解码:
- 1. 将每个 %XX 序列替换为对应的字节。
- 将得到的字节解释为 UTF-8 编码。
- 等效于 decodeURIComponent(input)。
HTML 实体(类型:html)
编码: 将这些字符替换为其命名的 HTML 实体:
解码: 反向映射——将每个 HTML 实体替换为其字面字符。
选项
- - type:base64 | url | html — 默认值:base64
- direction:encode | decode — 默认值:encode
示例
Base64 编码:
输入:Hello, World!
输出:SGVsbG8sIFdvcmxkIQ==
Base64 编码(Unicode):
输入:Héllo
输出:SMOpbGxv
Base64 解码:
输入:SGVsbG8sIFdvcmxkIQ==
输出:Hello, World!
URL 编码:
输入:name=John Doe&city=New York
输出:name%3DJohn%20Doe%26city%3DNew%20York
URL 解码:
输入:hello%20world%21
输出:hello world!
HTML 编码:
输入:
输出:<script>alert("XSS")</script>
HTML 解码:
输入:<h1>Hello & welcome</h1>
输出:
Hello & welcome
错误处理
- - 无效的 Base64 解码输入: 如果字符串包含 Base64 字母表之外的字符或填充不正确,报告:错误:无效的 Base64 字符串。请用户验证输入。
- 无效的 URL 编码解码输入: 如果 %XX 序列使用了非十六进制数字或序列不完整,报告:错误:无效的 URL 编码字符串。
- 空输入: 返回空字符串,并附注未提供任何输入。
- 二进制/非文本数据: 警告用户 Base64 编码二进制数据需要原始字节,而原始字节无法以纯文本形式提供——建议他们使用接受文件上传的工具。