Exemple
Calculer le hachage MD5 de la chaîne "Hello" :
<?php
$str = "Hello";
echo md5($str);
?>
»Exécuter exemple Définition et utilisation
Le md5() calcule la valeur de hachage MD5 d'une chaîne.
Le md5() fonction utilise RSA Data Security, Inc. MD5 algorithme Message-Digest.
De la RFC 1321 - L'algorithme MD5 Message-Digest: "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." des "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." d' "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." de "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA."
Pour calculer le hachage MD5 d'un fichier, utilisez la md5_file() fonction.
Syntaxe
md5( string,raw )
Paramètre | La description |
---|---|
string | Champs obligatoires. La chaîne à calculer |
raw | Optionnel. Indique le format de sortie hexadécimal ou binaire:
|
Détails techniques
Valeur de retour: | Retourne le hachage MD5 calculé sur la réussite, en cas d'échec |
---|---|
PHP Version: | 4+ |
changelog: | Le paramètre brut est devenu optionnel en PHP 5.0 |
autres exemples
Exemple 1
Imprimer le résultat de md5() :
<?php
$str = "Hello";
echo "The string: ".$str."<br>";
echo
"TRUE - Raw 16 character binary format: ".md5($str, TRUE)."<br>";
echo
"FALSE - 32 character hex number: ".md5($str)."<br>";
?>
»Exécuter exemple exemple 2
Imprimer le résultat de md5() , puis le tester:
<?php
$str = "Hello";
echo md5($str);
if (md5($str) ==
"8b1a9953c4611296a827abf8c47804d7")
{
echo "<br>Hello
world!";
exit;
}
?>
»Exécuter exemple <PHP chaîne de référence