php常用hash加密函數,phphash加密
本文執行個體講述了php常用hash加密函數。分享給大家供大家參考。具體分析如下:
複製代碼 代碼如下:$hash_list=hash_algos(); //返回註冊的hash規則列表
print_r($hash_list); //顯示結果
建立檔案以計算雜湊值:file_put_contents('example.txt', 'the quick brown fox jumped over the lazy dog.');
輸出雜湊值資訊:
複製代碼 代碼如下:echo hash_file('md5', 'example.txt');
$str="the quick brown fox jumped over the lazy dog."; //定義字串
echo hash('ripemd160',$str); //產生雜湊值
$ctx=hash_init('md5'); //初始化一個hash值
hash_update($ctx,'the quick brown fox'); //向雜湊值灌注資料
hash_update($ctx,'jumped over the lazy dog.'); //向雜湊值灌注資料
echo hash_final($ctx); //輸出最後的結果
$str="the quick brown fox jumped over the lazy dog."; //定義字串
$fp=tmpfile(); //建立一個臨時檔案
fwrite($fp,$str); //將字串寫入到臨時檔案
rewind($fp); //倒迴文件指標的位置
$ctx=hash_init('md5'); //初始化一個hash值
hash_update_stream($ctx,$fp); //向資料流中灌注資料
echo hash_final($ctx); //輸出結果
$str="the quick brown fox jumped over the lazy dog."; //定義字串
echo hash_hmac('ripemd160',$str,'secret'); //產生包含密鑰的hash值
/*建立一個檔案並將字串寫入其中*/
$file="example.txt"; //定義檔案名稱
$str=" the quick brown fox jumped over the lazy dog."; //定義字串
file_put_contents($file,$str); //向檔案中寫入字串
echo hash_hmac_file('md5',$file,'secret'); //產生一個包含密鑰的hash值
$ctx=hash_init('sha1'); //定義字串
hash_update($ctx,'the quick brown fox jumped over the lazy dog.'); //向雜湊值中灌注資料
echo hash_final($ctx); //輸出結果
希望本文所述對大家的PHP程式設計有所協助。
http://www.bkjia.com/PHPjc/916060.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/916060.htmlTechArticlephp常用hash加密函數,phphash加密 本文執行個體講述了php常用hash加密函數。分享給大家供大家參考。具體分析如下: 複製代碼 代碼如下: $hash_l...