пример
Вычислить SHA-1 хэш строки "Hello" :
<?php
$str = "Hello";
echo sha1($str);
?>
Выполнить пример » Определение и использование
sha1() функция вычисляет SHA-1 хэш строки.
sha1() функция использует США Secure Hash Algorithm 1.
Из RFC 3174 - США Secure Hash Algorithm 1: "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." , "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." , "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." , "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." , "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." , "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature." который "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature."
Совет: Для вычисления SHA-1 хэш файла, используйте sha1_file() функцию.
Синтаксис
sha1( string,raw )
параметр | Описание |
---|---|
string | Необходимые. Строка рассчитывается |
raw | Необязательный. Указать гекс или формат двоичного выхода:
|
Технические подробности
Возвращаемое значение: | Возвращает вычисленное SHA-1 хэш на успех, или FALSE при неудаче |
---|---|
PHP версии: | 4.3.0+ |
Changelog: | Сырья параметр стал необязательным в PHP 5.0 |
Еще примеры
Пример 1
Вывести результат sha1() :
<?php
$str = "Hello";
echo "The string: ".$str."<br>";
echo
"TRUE - Raw 20 character binary format: ".sha1($str, TRUE)."<br>";
echo
"FALSE - 40 character hex number: ".sha1($str)."<br>";
?>
Выполнить пример » Пример 2
Вывести результат sha1() , а затем проверить:
<?php
$str = "Hello";
echo sha1($str);
if (sha1($str) ==
"f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0")
{
echo "<br>Hello
world!";
exit;
}
?>
Выполнить пример » <String Reference PHP