пример
Вычислить MD5 хэш строки "Hello" :
<?php
$str = "Hello";
echo md5($str);
?>
Выполнить пример » Определение и использование
md5() функция вычисляет MD5 хэш строки.
md5() функция использует RSA Data Security, Inc. MD5 Message-Digest Algorithm.
Из RFC 1321 - The MD5 Message-Digest Algorithm: "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." - "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." в "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." в "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." , "The MD5 message-digest algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA."
Чтобы вычислить MD5 хэш файла, используйте md5_file() функцию.
Синтаксис
md5( string,raw )
параметр | Описание |
---|---|
string | Необходимые. Строка рассчитывается |
raw | Необязательный. Задает гекс или формат двоичного выхода:
|
Технические подробности
Возвращаемое значение: | Возвращает вычисленный хэш MD5 на успех, или FALSE при неудаче |
---|---|
PHP версии: | 4+ |
Changelog: | Сырья параметр стал необязательным в PHP 5.0 |
Еще примеры
Пример 1
Вывести результат 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>";
?>
Выполнить пример » Пример 2
Вывести результат md5() , а затем проверить:
<?php
$str = "Hello";
echo md5($str);
if (md5($str) ==
"8b1a9953c4611296a827abf8c47804d7")
{
echo "<br>Hello
world!";
exit;
}
?>
Выполнить пример » <String Reference PHP