Hashes/Cripto
HMAC Generator
Calcule o HMAC (Hash-based Message Authentication Code) de um texto ou arquivo com uma chave secreta — com oito algoritmos de uma vez: MD5, SHA-1, SHA-256, SHA-384, SHA-512, SHA3-256, SHA3-512, RIPEMD-160.
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.
Artigo sobre esta ferramenta: HMAC: em que um hash com chave difere de um hash comum
Perguntas frequentes
Qual é a diferença entre HMAC e um hash comum?
Um hash comum (como SHA-256 sozinho) só gera uma impressão digital dos dados, sem chave. O HMAC combina o hash com uma chave secreta, permitindo autenticar a origem da mensagem — só quem conhece a chave consegue gerar ou validar o mesmo HMAC.
Que tamanho de chave e algoritmo devo escolher?
Prefira SHA-256 ou superior para uso moderno; MD5 e SHA-1 permanecem aqui por compatibilidade, mas são desaconselhados para novos sistemas. A chave deve ser aleatória e ter comprimento igual ou maior que o tamanho de saída do hash escolhido.
Por que alguns algoritmos ficam indisponíveis em HTTP simples?
Os algoritmos HMAC-SHA usam a Web Crypto API do navegador, que só funciona em contextos seguros (HTTPS ou localhost). Os demais algoritmos, implementados sem essa API, continuam funcionando normalmente.
Por que não posso comparar um HMAC usando o operador de igualdade comum?
A comparação comum de strings para na primeira divergência, e o tempo de execução revela ao atacante quantos dos primeiros caracteres ele acertou (timing attack). São necessárias funções de comparação em tempo constante, como o hash_equals no PHP.
Posso usar a mesma chave para várias finalidades diferentes?
Não é recomendado. Se a mesma chave secreta for usada tanto para assinar webhooks quanto para outra finalidade, o comprometimento de um sistema compromete automaticamente o outro — para cada uso específico, vale gerar uma chave separada.