пример
Вычислить SHA-1 хэш текстового файла "test.txt" :
<?php
$filename = "test.txt";
$sha1file = sha1_file($filename);
echo $sha1file;
?>
Выход кода выше:
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
Определение и использование
sha1_file() функция вычисляет SHA-1 хэш файла.
sha1_file() функция использует США 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 хэш успеха, FALSE при неудаче.
Синтаксис
sha1_file( file,raw )
параметр | Описание |
---|---|
file | Необходимые. Файл необходимо рассчитать |
raw | Необязательный. Логическое значение, которое определяет формат гекс или двоичный выход:
|
Технические подробности
Возвращаемое значение: | Возвращает вычисленное SHA-1 хэш на успех, или FALSE при неудаче |
---|---|
PHP версии: | 4.3.0+ |
Changelog: | Сырья параметр стал необязательным в PHP 5.0 По состоянию на PHP 5.1, можно использовать sha1_file() с обертками, например sha1_file("http://w3ii.com/..") |
Еще примеры
Пример 1
Храните SHA-1 хэш "test.txt" в файле:
<?php
$sha1file = sha1_file("test.txt");
file_put_contents("sha1file.txt",$sha1file);
?>
Тест , если "test.txt" был изменен (то есть , если SHA-1 хэш был изменен):
<?php
$sha1file = file_get_contents("sha1file.txt");
if (sha1_file("test.txt") == $sha1file)
{
echo "The file is ok.";
}
else
{
echo "The file has been changed.";
}
?>
Выход выше код может быть:
The file is ok.
<String Reference PHP