CKTIS / PHP
hash_hmac()
Authentifie les octets d’un message avec une clé secrète et un hachage cryptographique.
Version : PHP 8.4; repository runtime, production runtime not attested
Syntaxe
hash_hmac(string $algo, string $data, string $key, bool $binary = false): stringAuthentifie les octets d’un message avec une clé secrète et un hachage cryptographique. Le résultat est en hexadécimal minuscule, ou en octets bruts avec true. En PHP 8 un algorithme inconnu ou non cryptographique déclenche ValueError. La vérification emploie la même clé et le même format.
Signature
hash_hmac(string $algo, string $data, string $key, bool $binary = false): string
Sortie de l’exemple
[32,true,false]
Exemples
<?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))]);
Résultat
[32,true,false]