定義和用法
的sha1()函數計算字符串的SHA-1散列。
該sha1()函數使用美國安全散列算法1。
從RFC 3174 -美國安全散列算法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哈希值,使用sha1_file()函數。
句法
sha1( string,raw )
參數 | 描述 |
---|---|
string | 需要。 要計算的字符串 |
raw | 可選的。 指定十六進制或二進制輸出格式:
|
技術細節
返回值: | 成功則返回計算的SHA-1散列,或FALSE的失敗 |
---|---|
PHP版本: | 4.3.0+ |
更新日誌: | 原始參數在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;
}
?>
運行示例» <PHP字符串參考