PHP md5() function
Mga halimbawa
Pagtutukoy ng MD5 hash ng string "Hello":
<?php $str = "Shanghai"; echo md5($str); ?>
Paglilinaw at paggamit
Ang md5() function ay nagtutukoy ng MD5 hash ng string.
Ang md5() function ay gumagamit ng seguridad ng RSA data, kasama ang algoritmo ng MD5 message digest.
Mga paliwanag mula sa RFC 1321 - Algoritmo ng MD5 Message Digest: Ang algoritmo ng MD5 Message Digest ay nagbibigay ng bawat haba ng impormasyon bilang input, at nagbabagong ito sa isang 128-bit na haba na "imprint ng impormasyon" o "message digest" na naglalarawan ng input, at nagbibigay ng resulta bilang ito. Ang algoritmo ng MD5 ay pinagdisenyo sa pangangailangan ng aplikasyon ng digital signature; sa aplikasyon ng digital signature, ang malaking file ay nangangalaga sa seguridad bago ito ay pinakikompress sa pamamagitan ng encryption (ang prosesong ito ay ginagawa sa pamamagitan ng pagtatakda ng pribadong key sa ilalim ng isang sistema ng password [tulad ng: RSA] sa ilalim ng pampublikong key).
To calculate the MD5 hash of a file, please use md5_file() Function.
Syntax
md5(string,raw)
Parameter | Description |
---|---|
string | Required. Specifies the string to be calculated. |
raw |
Optional. Specifies the hexadecimal or binary output format:
|
Technical Details
Return Value: | Returns the calculated MD5 hash if successful, or FALSE if failed. |
PHP Version: | 4+ |
Update Log: | In PHP 5.0,raw The parameter is optional. |
More Examples
Example 1
Output the result of md5():
<?php $str = "Shanghai"; echo "String: " . $str . "<br>"; echo "TRUE - Original 16 character binary format: " . md5($str, TRUE) . "<br>"; echo "FALSE - 32 character hexadecimal format: " . md5($str) . "<br>"; ?>
Example 2
Output the result of md5() and then test it:
<?php $str = "Shanghai"; echo md5($str); if (md5($str) == "5466ee572bcbc75830d044e66ab429bc") { echo "<br>Hello world!"; exit; } ?>