$hash_list=hash_algos();  //返回注冊(cè)的hash規(guī)則列表

print_r($hash_list); //顯示結(jié)果

創(chuàng)建文件以計(jì)算哈希值:file_put_contents('example.txt', 'the quick brown fox jumped over the lazy dog.');

輸出哈希值信息:

  1. echo hash_file('md5''example.txt'); 
  2.  
  3. $str="the quick brown fox jumped over the lazy dog.";      //定義字符串 
  4. echo hash('ripemd160',$str);           //生成哈希值 
  5.  
  6. $ctx=hash_init('md5');          //初始化一個(gè)hash值 
  7. hash_update($ctx,'the quick brown fox');       //向哈希值灌注數(shù)據(jù) 
  8. hash_update($ctx,'jumped over the lazy dog.');      //向哈希值灌注數(shù)據(jù) 
  9. echo hash_final($ctx);          //輸出最后的結(jié)果 
  10.  
  11. $str="the quick brown fox jumped over the lazy dog.";    //定義字符串 
  12. $fp=tmpfile();            //創(chuàng)建一個(gè)臨時(shí)文件 
  13. fwrite($fp,$str);            //將字符串寫入到臨時(shí)文件 
  14. rewind($fp);            //倒回文件指針的位置 
  15. $ctx=hash_init('md5');          //初始化一個(gè)hash值 
  16. hash_update_stream($ctx,$fp);         //向數(shù)據(jù)流中灌注數(shù)據(jù) 
  17. echo hash_final($ctx);          //輸出結(jié)果 
  18.  
  19.  
  20. $str="the quick brown fox jumped over the lazy dog.";    //定義字符串 
  21. echo hash_hmac('ripemd160',$str,'secret');      //生成包含密鑰的hash值 
  22.  
  23. /*創(chuàng)建一個(gè)文件并將字符串寫入其中*/ 
  24. $file="example.txt";          //定義文件名 
  25. $str=" the quick brown fox jumped over the lazy dog.";   //定義字符串 
  26. file_put_contents($file,$str);        //向文件中寫入字符串 
  27. echo hash_hmac_file('md5',$file,'secret');      //生成一個(gè)包含密鑰的hash值 
  28.  
  29. $ctx=hash_init('sha1');          //定義字符串 
  30. hash_update($ctx,'the quick brown fox jumped over the lazy dog.');  //向哈希值中灌注數(shù)據(jù) 
  31. echo hash_final($ctx);  //輸出結(jié)果 
  32. //開源代碼phpfensi.com
轉(zhuǎn)載請(qǐng)注明來(lái)源:php中常用hash加密函數(shù)

  哈爾濱品用軟件有限公司致力于為哈爾濱的中小企業(yè)制作大氣、美觀的優(yōu)秀網(wǎng)站,并且能夠搭建符合百度排名規(guī)范的網(wǎng)站基底,使您的網(wǎng)站無(wú)需額外費(fèi)用,即可穩(wěn)步提升排名至首頁(yè)。歡迎體驗(yàn)最佳的哈爾濱網(wǎng)站建設(shè)。