HMAC 签名生成器 HMAC Generator
使用密钥(Secret Key)对消息(Message)生成常见 HMAC 签名:HMAC-SHA256 / SHA-1 / SHA-384 / SHA-512。输出 Hex、Base64、Base64URL,并支持一键复制。
Generate common HMAC signatures using a secret key and a message. Outputs Hex, Base64 and Base64URL with copy buttons.
1. 输入参数 · Inputs
3. 使用说明 · Notes
-
HMAC 是什么?· What is HMAC?
HMAC(Hash-based Message Authentication Code)是一种基于“密钥 + 哈希函数”的消息认证码,用来验证消息未被篡改且来自持有同一密钥的一方。
HMAC is a keyed hash used to verify integrity and authenticity: the same secret key must be shared by both parties. -
为什么“同样的字看起来一样”却签名不同?· Why do signatures mismatch?
常见原因不是算法,而是字符串不一致:多一个空格、末尾多一行、换行符 CRLF vs LF、URL 编码差异、JSON 格式化(空格/换行)或字段顺序不同。
It’s usually not the algorithm—it’s the exact bytes. A single whitespace, trailing newline, CRLF vs LF, URL encoding differences, or JSON formatting/order changes everything. -
Hex / Base64 / Base64URL 有啥区别?· Hex vs Base64 vs Base64URL
Hex: 纯 0-9a-f,直观但更长;多用于文档示例和调试对照。Hex is readable but longer.
Base64: 更短、更常用于 HTTP 头或 JSON 字段(但包含 + / =)。Shorter, widely used in APIs.
Base64URL: 用于 URL/Token 场景,替换 “+ /” 并去掉 “=”。Safer in URLs and tokens. -
安全提醒 · Security tips
① 不要在不可信页面输入生产密钥;② 不要把签名当成“加密”——HMAC 只能验证完整性,不能隐藏内容;③ 如果你要签名 JSON,建议先用接口要求的“规范化格式”(canonical form)。
1) Don’t paste real production secrets into untrusted pages. 2) HMAC is not encryption—content is still visible. 3) Canonicalize payload exactly as required by the API spec. -
本工具如何计算?· How this tool computes
使用浏览器 Web Crypto API:将 Key 与 Message 以 UTF-8 编码为字节,然后按所选算法计算 HMAC,最后分别编码为 Hex / Base64 / Base64URL。所有计算在本地完成,不上传。
Uses the browser Web Crypto API: UTF-8 bytes → HMAC → encode to Hex/Base64/Base64URL. Everything runs locally; nothing is uploaded. -
兼容性说明 · Compatibility
现代浏览器均支持(Chrome/Edge/Firefox/Safari 新版本)。若你在老旧环境里看不到结果,可能是不支持 Web Crypto 或被策略禁用。
Works on modern browsers. If results don’t show, your environment may not support Web Crypto or it’s policy-restricted.
免责声明:本工具仅用于学习、调试与测试,不构成安全/合规建议。请根据你的业务规范与安全要求合理使用。
Disclaimer: For learning/testing/debugging only. This is not security or compliance advice.
