HMAC Generator|HMAC 签名工具

HMAC Generator|HMAC 签名工具

HMAC Generator HMAC 签名工具

输入密钥(Key)与消息(Message),选择算法(如 HMAC-SHA256),生成常用签名(Hex/Base64),适合做 API 签名、Webhook 校验、消息完整性验证。
Enter a key and a message, pick an algorithm (e.g., HMAC-SHA256), and get signatures in Hex/Base64 for API signing & verification.

1. 输入参数 · Inputs
SHA-256 是最常用选择;SHA-1 已不适合新系统(仅兼容旧接口时使用)。
SHA-256 is the common default. SHA-1 is legacy and should be avoided for new designs.
小提示:很多 API 文档写的“secret”是文本(UTF-8);有些系统给的是随机字节,会用 Hex/Base64 形式发给你。
Tip: Many API docs treat the secret as UTF-8 text; others provide random bytes encoded as Hex/Base64.
Key 很敏感:建议只用测试 Key;不要把真实生产密钥粘贴到不可信页面。
Keys are sensitive: use test keys when possible; avoid pasting production secrets into untrusted pages.
注意:空格、换行、JSON 字段顺序、URL 编码(%2F vs /)都会影响签名结果。
Note: spaces, newlines, JSON field order, and URL encoding will all change the signature.
如果你在对接接口签名,请确保签名原文与服务端一致(包含换行符、是否末尾有 \n、是否排序参数等)。
For API signing, make sure your canonical string matches the server’s rules (newlines, trailing \n, param sorting, etc.).
部分接口要求 Hex 大写或带前缀(例如 0x…)。如文档有明确说明,以文档为准。
Some APIs require uppercase Hex or a prefix like 0x. Follow your API spec.
3. 使用说明 · Notes
  • HMAC 是什么? · What is HMAC?
    HMAC(Hash-based Message Authentication Code)是“带密钥的哈希认证码”。它把密钥 Key消息 Message结合起来计算,输出固定长度的签名。
    HMAC combines a secret key and a message to produce a fixed-length signature for integrity & authenticity checks.
  • HMAC ≠ 单纯 Hash · HMAC is not just a hash
    单纯 SHA-256(message) 没有密钥,任何人都能算;HMAC-SHA256(key, message) 需要同一把 key 才能生成/验证。
    SHA-256(message) is public; anyone can compute it. HMAC requires the shared secret key to sign/verify.
  • 为什么你算出来不一样?最常见原因 · Why does my result differ?
    1)服务端要求把参数按字典序排序;2)要求 URL 编码(或要求不编码);3)原文末尾是否带换行;4)JSON 序列化规则不同(空格/缩进/字段顺序);5)Key 实际是 Hex/Base64 字节而不是“文本”。
    Common causes: canonicalization differences (param sorting), URL encoding rules, trailing newline, JSON serialization differences, or the key being bytes (Hex/Base64) rather than plain text.
  • 怎么用于 Webhook 校验? · How to verify a webhook?
    通常流程:服务端发送 payload + signature;你用相同的 secret 对 payload 计算 HMAC,再与 signature 对比。注意对比时建议使用“常数时间比较”(防侧信道)。
    Typical flow: provider sends payload + signature; you compute HMAC with the same secret and compare. Use constant-time comparison to reduce timing attacks.
  • 安全建议 · Security tips
    不要用真实生产密钥做在线测试;优先在本地离线环境校验。若必须粘贴,请确认页面无网络请求、无第三方脚本。
    Avoid testing production secrets online. Prefer offline/local verification. If you must paste, ensure the page has no network calls and no third-party scripts.
  • 兼容性 · Compatibility
    本工具使用浏览器 Web Crypto API(crypto.subtle)。现代 Chrome/Edge/Firefox 基本可用;若在老旧浏览器/某些 WebView 不支持,会提示错误。
    This tool uses Web Crypto API (crypto.subtle). Modern browsers should work; older browsers/WebViews may not.

免责声明:本工具仅用于学习与调试,结果取决于你输入的“签名原文”与服务端规则是否一致,不构成任何安全或加密方案建议。
Disclaimer: For learning/debugging only. Results depend on whether your canonical string matches the server’s spec. Not a security design recommendation.