PHP實現增強性mhash

來源:互聯網
上載者:User
PHP如何?增強性mhash?本文主要介紹了PHP實現的增強性mhash函數,使用預設mhash函數卻報錯,找到了兩個解決方案。希望對大家有所協助。

今天使用php的加密函數mhash 的時候,報錯: Fatal error : Call to undefined function mhash()

mhash是php的內建函數但是使用卻報錯..

一番研究總結兩種方法:

1,匯入php_mhash.dll擴充檔案,除此之外還要匯入 libmhash.dll (mhash 庫的載入依賴這個檔案) ,

在 Apache 的設定檔 Httpd.conf 中載入 LoadFile C:/php/libmhash.dll” 。

2,使用自訂的mhash增強函數。

function hmac_md5($key, $data){    if (extension_loaded('mhash'))    {        return bin2hex(mhash (MHASH_MD5, $data, $key));    }    $b = 64;    if (strlen($key) > $b)    {        $key = pack('H*', md5($key));    }    $key  = str_pad($key, $b, chr(0x00));    $ipad = str_pad('', $b, chr(0x36));    $opad = str_pad('', $b, chr(0x5c));    $k_ipad = $key ^ $ipad;    $k_opad = $key ^ $opad;    return md5($k_opad . pack('H*', md5($k_ipad . $data)));}


hmac_md5 函數裡的參數$key和$data對應mhash原有的3,2參數。

這兩個方法都可以順利的使用上php 的mhash 加密函數

相關推薦:

PHP加密擴充庫-Mhash擴充庫執行個體用法詳解

PHP中如何安裝 Mhash擴充庫_PHP教程

PHP formhash具體如何做

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.