php常用hash加密函數,phphash加密_PHP教程

來源:互聯網
上載者:User

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...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.