2012-10-09 51 views
1

mcrypt_encrypt manual page說:替代mhash_keygen_s2k()

建議使用mhash函數來創建一個字符串鍵。

introduction of the mhash手冊上說:

注:該擴展是通過哈希過時。

不過,我能找到的相當有用mhash_keygen_s2k()功能最接近的東西就是hash_pbkdf2()功能。但是,我甚至不確定它是否適合這項工作,因爲它只存在於SVN中。

那麼,我可以依靠mhash擴展名,否則它最終會被棄用和丟棄?如果是這樣,是否還有其他內置函數?還是我必須自己實現Salted S2K算法?

+0

錯誤https://bugs.php.net/bug.php?id=63250提交。 –

+0

你也可以檢查這個問題的答案:http://stackoverflow.com/questions/11965708/php-hash-pbkdf2-function然後包括一個PBKDF2實現的PHP。 –

回答

0

我結束了偷看mhash源代碼移植到這個PHP:

function keygen_s2k($hash, $password, $salt, $bytes) 
{ 
    $result = false; 

    if (extension_loaded('hash') === true) 
    { 
     foreach (range(0, ceil($bytes/strlen(hash($hash, null, true))) - 1) as $i) 
     { 
      $result .= hash($hash, str_repeat("\0", $i) . str_pad(substr($salt, 0, 8), 8, "\0", STR_PAD_RIGHT) . $password, true); 
     } 

     $result = substr($result, 0, intval($bytes)); 
    } 

    return $result; 
} 

如果有人知道任何其他內置功能,我還是想聽到它。