ハッシュ/暗号
HMAC Generator
秘密鍵を使ってテキストやファイルのHMAC(Hash-based Message Authentication Code)を計算 — MD5、SHA-1、SHA-256、SHA-384、SHA-512、SHA3-256、SHA3-512、RIPEMD-160の8種類のアルゴリズムを一度に。
HMAC (Hash-based Message Authentication Code) is a hash computed together with a secret key, proving a message hasn't changed and was sent by someone who knows that key. Unlike a plain hash, an HMAC can't be forged without knowing the secret.
How to use it
- Enter text or a file and a secret key — the HMAC is computed instantly with eight algorithms at once (MD5, SHA-1, SHA-2, SHA3, RIPEMD-160).
- Copy the variant you need to verify a signature or compare against an expected value.
- The same input and key always produce the same HMAC — handy for checking against a signature received from another system.
Common uses
- Verifying a webhook signature from a payment service or API (most sign the payload with HMAC-SHA256).
- Generating a request signature for an API that requires HMAC authentication.
- Debugging a mismatched signature — checking the key, input encoding, and algorithm one at a time.
Things to keep in mind
HMAC protects against tampering and confirms the sender's authenticity, but it doesn't encrypt the message itself — the content stays readable.
A mismatched HMAC is most often caused by different data encoding (e.g. JSON field order) or a stray whitespace or line break, not by a bug in the algorithm itself.
よくある質問
HMACと単純なハッシュの違いは何ですか?
単純なハッシュはデータが改ざんされていないことしか証明しません。HMACはさらに秘密鍵を使うため、完全性に加えて送信者が共有秘密を知っていたことも証明します。鍵を知らない人はアルゴリズムを知っていても有効なHMACを生成できません。
HMACにはどのハッシュアルゴリズムを選ぶべきですか?
HMAC-SHA256が堅実な現代的デフォルトです。HMAC-MD5やHMAC-SHA1のような古い選択肢もHMACとしては特に破られていませんが、新しいシステムにはSHA-256以上が推奨されます。
秘密鍵はどこかに送信されますか?
いいえ。HMACはWeb Crypto APIを使ってブラウザ内で完全に計算されます。鍵とメッセージはデバイスから外に出ることはありません。
なぜHMACを単純な等価演算子で比較してはいけないのですか?
単純な文字列比較は最初の不一致で処理を止めるため、比較にかかった時間から攻撃者は最初の何文字を正しく推測できたかを知ることができます(timing attack)。PHPのhash_equalsのような定数時間比較関数が必要です。
同じ鍵を複数の異なる目的で使い回してもよいですか?
推奨されません。同じ秘密鍵をウェブフックの署名と他の目的の両方に使用している場合、一方のシステムが侵害されるともう一方も自動的に侵害されます——目的ごとに個別の鍵を生成すべきです。