Hash/Crittografia
HMAC Generator
Calcola l'HMAC (Hash-based Message Authentication Code) di un testo o file con una chiave segreta — con otto algoritmi contemporaneamente: 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.
Articolo su questo strumento: HMAC: in cosa differisce un hash con chiave da un hash normale
Domande frequenti
Qual è la differenza tra HMAC e un hash semplice?
Un hash semplice dimostra solo che i dati non sono stati alterati; HMAC usa inoltre una chiave segreta, quindi dimostra sia l'integrità sia che il mittente conosceva il segreto condiviso — senza la chiave nessuno può produrre un HMAC valido anche conoscendo l'algoritmo.
Quale algoritmo di hash dovrei scegliere per HMAC?
HMAC-SHA256 è una solida scelta moderna predefinita. Opzioni più vecchie come HMAC-MD5 o HMAC-SHA1 non sono ancora violate come HMAC specificamente, ma per i nuovi sistemi si consiglia SHA-256 o superiore.
La mia chiave segreta viene inviata da qualche parte?
No. L'HMAC viene calcolato interamente nel tuo browser tramite la Web Crypto API — la chiave e il messaggio non lasciano mai il tuo dispositivo.
Perché non si può confrontare un HMAC con un normale operatore di uguaglianza?
Il normale confronto di stringhe si ferma alla prima differenza, e il tempo di esecuzione rivela all'attaccante quanti dei primi caratteri ha indovinato correttamente (timing attack). Servono funzioni di confronto a tempo costante, come hash_equals in PHP.
Si può usare la stessa chiave per più scopi diversi?
Non è consigliato. Se la stessa chiave segreta viene usata sia per firmare i webhook sia per un altro scopo, la compromissione di un sistema compromette automaticamente anche l'altro — per ogni uso specifico è meglio generare una chiave separata.