返回顶部
e

encoding-formats编码格式转换

Encode, decode, and convert between data formats. Use when working with Base64, URL encoding, hex, Unicode, JWT tokens, hashing, checksums, or converting between serialization formats like JSON, MessagePack, and protobuf wire format.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
1,913
下载量
免费
免费
1
收藏
概述
安装方式
版本历史

encoding-formats

编码与格式

对常见格式的数据进行编码、解码和检查。涵盖Base64、URL编码、十六进制、Unicode、JWT、哈希、校验和以及序列化格式。

使用场景

  • - 从API响应或配置中解码Base64字符串
  • 为HTTP请求对参数进行URL编码
  • 检查二进制数据的十六进制转储
  • 解码JWT令牌以查看声明
  • 计算或验证文件校验和
  • 在字符编码之间转换(UTF-8、Latin-1等)
  • 理解线路格式(protobuf、MessagePack)

Base64

编码与解码

bash

编码字符串


echo -n Hello, World! | base64

SGVsbG8sIFdvcmxkIQ==

解码字符串

echo SGVsbG8sIFdvcmxkIQ== | base64 -d

Hello, World!

编码文件

base64 image.png > image.b64 cat file.bin | base64

解码文件

base64 -d image.b64 > image.png

Base64url(URL安全变体:+ → -,/ → _,无填充)

echo -n Hello | base64 | tr +/ -_ | tr -d =

Base64url解码

echo SGVsbG8 | tr -_ +/ | base64 -d

代码实现

javascript
// JavaScript(浏览器 + Node.js 16+)
btoa(Hello); // SGVsbG8=
atob(SGVsbG8=); // Hello

// Node.js Buffer
Buffer.from(Hello).toString(base64); // SGVsbG8=
Buffer.from(SGVsbG8=, base64).toString(); // Hello

// 二进制数据
Buffer.from(binaryData).toString(base64);
Buffer.from(b64String, base64);

python

Python


import base64

base64.b64encode(bHello).decode() # SGVsbG8=
base64.b64decode(SGVsbG8=) # bHello

URL安全的Base64

base64.urlsafe_b64encode(bHello).decode() base64.urlsafe_b64decode(SGVsbG8=)

URL编码

编码与解码

bash

Python单行命令


python3 -c from urllib.parse import quote; print(quote(hello world & foo=bar))

hello%20world%20%26%20foo%3Dbar

解码

python3 -c from urllib.parse import unquote; print(unquote(hello%20world%20%26%20foo%3Dbar))

hello world & foo=bar

curl 使用 --data-urlencode 自动处理

curl -G --data-urlencode q=hello world & more https://api.example.com/search

代码实现

javascript
// JavaScript
encodeURIComponent(hello world & foo=bar);
// hello%20world%20%26%20foo%3Dbar

decodeURIComponent(hello%20world%20%26%20foo%3Dbar);
// hello world & foo=bar

// encodeURI 与 encodeURIComponent 的区别:
encodeURI(https://example.com/path?q=hello world);
// https://example.com/path?q=hello%20world(保留URL结构)
encodeURIComponent(https://example.com/path?q=hello world);
// https%3A%2F%2Fexample.com%2Fpath%3Fq%3Dhello%20world(编码所有内容)

python
from urllib.parse import quote, unquote, urlencode

quote(hello world) # hello%20world
unquote(hello%20world) # hello world
urlencode({q: hello world, page: 1}) # q=hello+world&page=1

十六进制

查看与转换

bash

文件十六进制转储


xxd file.bin | head -20
xxd -l 64 file.bin # 仅前64字节

十六进制转储(紧凑,无ASCII)

xxd -p file.bin

十六进制转二进制

echo 48656c6c6f | xxd -r -p

Hello

od(替代方案)

od -A x -t x1z file.bin | head -20

hexdump

hexdump -C file.bin | head -20

Python

python3 -c print(bytes.fromhex(48656c6c6f).decode()) # Hello python3 -c print(Hello.encode().hex()) # 48656c6c6f

代码实现

javascript
// JavaScript
Buffer.from(Hello).toString(hex); // 48656c6c6f
Buffer.from(48656c6c6f, hex).toString(); // Hello

// 数字转十六进制
(255).toString(16); // ff
parseInt(ff, 16); // 255

python

Python


Hello.encode().hex() # 48656c6c6f
bytes.fromhex(48656c6c6f).decode() # Hello
hex(255) # 0xff
int(ff, 16) # 255

Unicode

检查字符

bash

显示Unicode码点


echo -n Hello 世界 | python3 -c
import sys
for char in sys.stdin.read():
print(fU+{ord(char):04X} {char} {char.encode(\utf-8\).hex()})

U+0048 H 48


U+0065 e 65


...


U+4E16 世 e4b896


U+754C 界 e7958c

将Unicode转义转换为字符

printf \u0048\u0065\u006c\u006c\u006f # Hello echo -e \xE4\xB8\x96\xE7\x95\x8C # 世界

文件编码检测

file -bi document.txt

text/plain; charset=utf-8

编码转换

bash

在编码之间转换


iconv -f ISO-8859-1 -t UTF-8 input.txt > output.txt
iconv -f UTF-16 -t UTF-8 input.txt > output.txt

列出可用编码

iconv -l

Python

python3 -c with open(latin1.txt, r, encoding=iso-8859-1) as f: content = f.read() with open(utf8.txt, w, encoding=utf-8) as f: f.write(content)

常见Unicode问题

BOM(字节顺序标记):
UTF-8 BOM:文件开头的 EF BB BF
移除:sed -i 1s/^\xEF\xBB\xBF// file.txt

规范化(NFC vs NFD):
é 可以是 U+00E9(一个字符)或 U+0065 U+0301(e + 组合重音)
Python:import unicodedata; unicodedata.normalize(NFC, text)

乱码(编码错误):
café 显示为 café → 文件是UTF-8但被当作Latin-1读取
修复:使用正确的编码重新读取

JWT(JSON Web令牌)

解码JWT

bash

JWT由点分隔的3部分组成:header.payload.signature


每部分都是Base64url编码

解码头部和负载

TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

解码头部

echo $TOKEN | cut -d. -f1 | tr -_ +/ | base64 -d 2>/dev/null | jq

{alg:HS256,typ:JWT}

解码负载

echo $TOKEN | cut -d. -f2 | tr -_ +/ | base64 -d 2>/dev/null | jq

{sub:1234567890,name:John Doe,iat:151623902

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 encoding-formats-1776365851 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 encoding-formats-1776365851 技能

通过命令行安装

skillhub install encoding-formats-1776365851

下载

⬇ 下载 encoding-formats v1.0.0(免费)

文件大小: 5.17 KB | 发布时间: 2026-4-17 15:08

v1.0.0 最新 2026-4-17 15:08
Initial release: Base64, URL encoding, hex, Unicode, JWT decoding, hashing/checksums, serialization format conversion, auto-decode script

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部