php常用hash加密函數(shù)
本文實(shí)例講述了php常用hash加密函數(shù)。分享給大家供大家參考。具體分析如下:
print_r($hash_list); //顯示結(jié)果
創(chuàng)建文件以計(jì)算哈希值:file_put_contents('example.txt', 'the quick brown fox jumped over the lazy dog.');
輸出哈希值信息:
$str="the quick brown fox jumped over the lazy dog."; //定義字符串
echo hash('ripemd160',$str); //生成哈希值
$ctx=hash_init('md5'); //初始化一個(gè)hash值
hash_update($ctx,'the quick brown fox'); //向哈希值灌注數(shù)據(jù)
hash_update($ctx,'jumped over the lazy dog.'); //向哈希值灌注數(shù)據(jù)
echo hash_final($ctx); //輸出最后的結(jié)果
$str="the quick brown fox jumped over the lazy dog."; //定義字符串
$fp=tmpfile(); //創(chuàng)建一個(gè)臨時(shí)文件
fwrite($fp,$str); //將字符串寫入到臨時(shí)文件
rewind($fp); //倒回文件指針的位置
$ctx=hash_init('md5'); //初始化一個(gè)hash值
hash_update_stream($ctx,$fp); //向數(shù)據(jù)流中灌注數(shù)據(jù)
echo hash_final($ctx); //輸出結(jié)果
$str="the quick brown fox jumped over the lazy dog."; //定義字符串
echo hash_hmac('ripemd160',$str,'secret'); //生成包含密鑰的hash值
/*創(chuàng)建一個(gè)文件并將字符串寫入其中*/
$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'); //生成一個(gè)包含密鑰的hash值
$ctx=hash_init('sha1'); //定義字符串
hash_update($ctx,'the quick brown fox jumped over the lazy dog.'); //向哈希值中灌注數(shù)據(jù)
echo hash_final($ctx); //輸出結(jié)果
希望本文所述對(duì)大家的PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
PHP中include()與require()的區(qū)別說明
本文主要介紹了PHP中include()與require()的區(qū)別。具有很好的參考價(jià)值,下面跟著小編一起來看下吧2017-02-02PHP以指定字段為索引返回?cái)?shù)據(jù)庫所取的數(shù)據(jù)數(shù)組
本文與大家分享幾個(gè)使用得PHP編程技巧,有些技巧是在看別人代碼的時(shí)候?qū)W來的,有些是自己總結(jié)的,下面為大家介紹下以特定字段為索引,返回?cái)?shù)據(jù)庫取的數(shù)據(jù)數(shù)組,感興趣的朋友可以了解下哈2013-06-06PHP如何刪除關(guān)聯(lián)數(shù)組中鍵值
在本篇文章里小編給大家整理的是一篇關(guān)于PHP刪除關(guān)聯(lián)數(shù)組中鍵值的方法,有需要的朋友們可以學(xué)習(xí)參考下。2021-08-08