【问题标题】:Converting an blowfish encryption algo from php to python将河豚加密算法从 php 转换为 python
【发布时间】:2013-07-05 05:52:10
【问题描述】:

我有一个用于我的网站的真正简单的加密。我正在尝试将我的所有代码从 php 转换为 python,但我不知道如何让 python 产生与 php 对这段代码所做的相同的输出。

function myhash($word){
  $salt = "$2a$06$" . substr(sha1($word) , 0, 22) . "$";
  return crypt($word, $salt);
}

鉴于我已经使用此加密存储了相当多的密码,因此进行新的加密将是愚蠢的。怎么办?

【问题讨论】:

标签: php python encryption salt blowfish


【解决方案1】:

没有内置河豚。如果您可以使用其他模块,请尝试bcrypt,它完全符合您的需要。所以函数将是:

import hashlib
import brypt
def myhash(word):
    salt = "$2a$06$" + hashlib.sha1(word).hexdigest()[0:22] + "$"
    return bcrypt.hashpw(word, salt)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    • 2012-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多