CKTIS / PHP
hash_hmac()
Autentica i byte del messaggio con una chiave segreta e un hash crittografico.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
hash_hmac(string $algo, string $data, string $key, bool $binary = false): stringAutentica i byte del messaggio con una chiave segreta e un hash crittografico. Restituisce testo esadecimale minuscolo oppure byte grezzi con true. In PHP 8 un algoritmo ignoto o non crittografico causa ValueError. La verifica richiede la stessa chiave e lo stesso formato.
Firma
hash_hmac(string $algo, string $data, string $key, bool $binary = false): string
Output dell’esempio
[32,true,false]
Esempi
<?php
$tag=hash_hmac("sha256","batch=42","example-key",true);
echo json_encode([strlen($tag),hash_equals($tag,hash_hmac("sha256","batch=42","example-key",true)),hash_equals($tag,hash_hmac("sha256","batch=43","example-key",true))]);
Risultato
[32,true,false]