(PHP 4 >= 4.3.0, PHP 5)
sha1 — 計算字符串的 sha1 散列值
說明
string sha1 ( string$str
[, bool $raw_output
= false
] )
利用» 美國安全散列算法 1 計算字符串的 sha1 散列值。
參數
str
輸入字符串。
raw_output
如果可選的 raw_output
參數被設置為 TRUE
,那么 sha1 摘要將以 20 字符長度的原始格式返回,否則返回值是一個 40 字符長度的十六進制數字。
返回值
返回 sha1 散列值字符串。
更新日志
版本
說明
5.0.0
新增 raw_output
參數。
范例
Example #1 sha1() 范例
<?php
$str = 'apple';
if (sha1($str) === 'd0be2dc421be4fcd0172e5afceea3970e2f3d940') {
echo "Would you like a green or red apple?";
}
?>
注釋
Note:
Secure password hashing
由于此函數依賴的算法已不足夠復雜,不推薦使用此函數對明文密碼加密。詳細內容參見這里。
參見
sha1_file() - 計算文件的 sha1 散列值 crc32() - 計算一個字符串的 crc32 多項式 md5() - 計算字符串的 MD5 散列值 hash() - Generate a hash value (message digest)