PHP MD5 () function

Source: Internet
Author: User
Tags md5 md5 digest md5 hash



PHP String function


Instance


Computes the MD5 hash of the string "Hello":


<?php
$str = "Shanghai";
echo md5($str);
?>


Running an instance


Definition and usage


The MD5 () function computes the MD5 hash of the string.



The MD5 () function uses RSA data security, including MD5 Digest to algorithm.



Explanation from RFC 1321-MD5 Digest to algorithm: MD5 Digest to the algorithm will be arbitrary length of information as input value, and convert it into a 128-bit length of "fingerprint Information" or "Digest to" value to represent this input value, and with the converted value as the result. The MD5 algorithm is designed primarily for digitally signed applications, where large files are compressed in a secure manner prior to encryption (where encryption is done by setting a private key under the public key of a cryptographic system, such as RSA).



To calculate the MD5 hash of a file, use the Md5_file () function.


Grammar
MD5 (string,raw)
Parameters Description
String Necessary. Specifies the string to be computed.
Raw

Optional. Specify hexadecimal or binary output formats:

  • TRUE-Original 16 character binary format
  • FALSE-Default. 32-character hexadecimal number
Technical details
return value: Returns the computed MD5 hash if successful, or FALSE if it fails.
PHP version: 4 +
Update log: In PHP 5.0, theraw parameter becomes optional.
More examples of examples 1


Results of output MD5 ():


 
<?php
$str = "Shanghai";
Echo "string:".$str."<br>";
Echo "TRUE - original 16 character binary format: ".md5($str, TRUE)."<br>";
Echo "FALSE - 32 characters in hexadecimal format: ".md5($str)."<br>";
?>


Running an instance


Example 2


Output the result of MD5 () and test it:


<?php
$str = "Shanghai";
echo md5($str);

if (md5($str) == "5466ee572bcbc75830d044e66ab429bc")
  {
  echo "<br>Hello world!";
  exit;
  }
?>


PHP MD5 () function


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.