PHP md5 () function
Examples
Calculation string "Hello" MD5 hash:
$str = "Hello";
echo md5($str);
?>
Running instance »
Definition and Usage
md5 () function calculates the MD5 hash of a string.
md5 () function uses the RSA Data Security, including the MD5 message digest algorithm.
RFC 1321 interpretation from - MD5 message digestalgorithm:MD5message digest algorithm of arbitrary length message as input, and converts it into a 128-bit length of the "fingerprint" or "message digest" value to represent the enter a value, and the converted value as a result.MD5 algorithm is mainly for digital signature applications designed; in this digital signature applications, large files will be encrypted (encryption process here is through a password system under: public-key [such as RSA] under setting the private key and completed) in a secure manner prior to compression.
To calculate the MD5 hash of a file, use md5_file () function.
grammar
参数 | 描述 |
---|---|
string | 必需。规定要计算的字符串。 |
raw | 可选。规定十六进制或二进制输出格式:
|
technical details
return value: | If successful calculated MD5 hash, if it fails it returns FALSE. |
---|---|
PHP version: | 4+ |
Update log: | In PHP 5.0 in, raw parameter becomes optional. |
More examples
Example 1
Output md5 () result:
$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>";
?>
Running instance »
Example 2
Results output md5 () of and test it:
$str = "Hello";
echo md5($str);
if (md5($str) == "8b1a9953c4611296a827abf8c47804d7")
{
echo "<br>Hello world!";
exit;
}
?>
Running instance »
PHP String Reference