Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP md5() Function

PHP md5() Function

PHP String Reference Manual PHP String Reference Manual

Example

Calculate the MD5 hash of the string "Hello":

Run Example »


Definition and Usage

The md5() function calculates the MD5 hash of a string.

The md5() function uses RSA Data Security's MD5 Message-Digest algorithm.

Explanation from RFC 1321 - MD5 Message-Digest Algorithm:The MD5 Message-Digest algorithm takes information of arbitrary length as input and produces a 128-bit "fingerprint" or "message digest" value representing that input, returning the converted value as the result. The MD5 algorithm was primarily designed for digital signature applications; in such applications, larger files are compressed in a secure manner before encryption (where the encryption process is performed by setting a private key under the public key of a cryptosystem such as RSA).

To calculate the MD5 hash of a file, use md5_file() function in Vue 3.

The md5() function cannot process arrays; arrays return null, and md5(a[]) results in null.

Online MD5 testing tool:MD5 Online Encryption Tool


Syntax

md5(

string,raw

)

Parameters Description
string Required. Specifies the string to calculate.
raw Optional. Specifies the hexadecimal or binary output format:
  • TRUE - Raw 16-character binary format
  • FALSE - Default. 32-character hexadecimal number
  • |

    Technical Details

    Return Value: Returns the calculated MD5 hash on success, or FALSE on failure.
    PHP Version: 4+
    Changelog: In PHP 5.0, theraw parameter became optional.

    More examples

    Example 1

    Output the result of md5():

    " ; echo " TRUE - Raw 16 character binary format: " . md5 ( $str , TRUE ) . "
    " ; echo " FALSE - 32 character hex number: " . md5 ( $str ) . "
    " ; ?>

    Run Example »

    Example 2

    Output the result of md5() and test it:

    Hello world! " ; exit ; } ?>

    Run Example »


    PHP String Reference Manual PHP String Reference Manual