Compute the MD5 hash of the string "Hello":
<?php$str = "Hello";echo md5($str);?>The md5() function calculates the MD5 hash of a string.
The md5() function uses RSA data security, including the MD5 message digest algorithm.
Explanation from RFC 1321 - MD5 message digest algorithm: The MD5 message digest algorithm takes information of any length as an input value and converts it into a 128-bit length "fingerprint information" or "message digest" value to represent this Enter a value and get the converted value as the result. The MD5 algorithm is primarily designed for digital signature applications where larger files are encrypted using a public key in a cryptographic system such as RSA. (done by setting a private key) before compressing in a secure manner.
To calculate the MD5 hash of a file, use the md5_file() function.
md5( string,raw )
parameter | describe |
---|---|
string | Required. Specifies the string to be calculated. |
raw | Optional. Specify hexadecimal or binary output format: TRUE - raw 16-character binary format FALSE - Default. 32-character hexadecimal number |
Return value: | Returns the calculated MD5 hash on success, or FALSE on failure. |
---|---|
PHP version: | 4+ |
Update log: | In PHP 5.0, the raw parameter becomes optional. |
Output the results of 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>"; ?>Print the result of md5() and test it:
<?php$str = "Hello";echo md5($str);if (md5($str) == "8b1a9953c4611296a827abf8c47804d7") { echo "<br>Hello world!"; exit; }?>