dongqiya9552 2012-10-09 17:38
浏览 51
已采纳

mhash_keygen_s2k()的替代方案

The mcrypt_encrypt manual page says that:

It is recommended to use the mhash functions to create a key from a string.

But the introduction of the mhash manual says that:

Note: This extension is obsoleted by Hash.

However, the closest thing I could find to the rather useful mhash_keygen_s2k() function was the hash_pbkdf2() function. However, I'm not even sure if it fits the job since it only exists in the SVN.

So, can I rely on the mhash extension, or it will eventually become deprecated and dropped? If so, is there any alternative built-in function or do I have to implement the Salted S2K algorithm myself?

  • 写回答

1条回答 默认 最新

  • douzhi9635 2012-10-09 20:57
    关注

    I ended up peeking into mhash source code porting this to 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;
    }
    

    If anyone knows any alternative built-in function, I would still like to hear about it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器