首頁  >  文章  >  後端開發  >  php常用hash加密函數

php常用hash加密函數

伊谢尔伦
伊谢尔伦原創
2016-11-24 14:11:481185瀏覽

本文實例講述了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); //输出结果

🎜🎜
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn