Fonctions PHP - mhash ()

le mhash() fonction peut calculer un hachage.

Syntaxe

string mhash( int $hash , string $data [, string $key ] )

La fonction mhash () peut appliquer une fonction de hachage spécifiée par hachage aux données.

La fonction mhash () peut renvoyer le hachage résultant (également appelé digest) ou HMAC sous forme de chaîne, ou false en cas d'erreur.

Exemple 1

<?php
   $mes01 = "Water dropping day by day wears the hardest rock away.";

   $alg01 = MHASH_SHA256; // ALGO = 17

   $ctl01 = "6r0pp1n9";

   $hmacD = mhash($alg01, $mes01, $ctl01);
   $hmacH = bin2hex($hmacD);

   echo "ALGO ( " . $alg01 . " )ORIGINAL MESSAGE:" . $mes01 
        . "MHASH RAW-BINARY:" . $hmacD 
        . "MHASH HEXADECIMAL:" . $hmacH;
?>

Production

ALGO ( 17 )ORIGINAL MESSAGE:Water dropping day by day wears the hardest rock away.MHASH RAW-BINARY:@�KLe.��!��ɧd�u����b��f���2�MHASH HEXADECIMAL:021340804b4c652ea4b121c0d5c9a764dd75f7bbfbfc0262e7dc66899cfa32ef

Exemple 2

<?php
   $mes02 = "Water dropping day by day wears the hardest rock away.";

   $nbrh = mt_rand(0, 33);

   $alg02 = $nbrh;
   $ctl02 = "6r0pp1n9";

   $hmacD = @mhash($alg02, $mes02, $ctl02);
   $hmacH = bin2hex($hmacD);

   echo "ALGO ( " . $alg02 . " )ORIGINAL MESSAGE:" . $mes02 
        . "MHASH RAW-BINARY:" . $hmacD 
        . "MHASH HEXADECIMAL:" . $hmacH;
?>

Production

ALGO ( 11 )ORIGINAL MESSAGE:Water dropping day by day wears the hardest rock away.MHASH RAW-BINARY:���E�R^x�*���c|Jt��\KMHASH HEXADECIMAL:b7d4e00345cc525e780403cf2af593fd637c4a74c9e85c4b