basic.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:ForgeryPy3 作者: pilosus 项目源码 文件源码
def encrypt(password='password', salt=None):
    """
    Return SHA1 hexdigest of a password (optionally salted with a string).


    """
    if not salt:
        salt = str(datetime.utcnow())

    try:
        #  available for python 2.7.8 and python 3.4+
        dk = hashlib.pbkdf2_hmac('sha1', password.encode(), salt.encode(), 100000)
        hexdigest = binascii.hexlify(dk).decode('utf-8')
    except AttributeError:
        # see https://pymotw.com/2/hashlib/
        # see https://docs.python.org/release/2.5/lib/module-hashlib.html
        dk = hashlib.sha1()
        dk.update(password.encode() + salt.encode())
        hexdigest = dk.hexdigest()
    return hexdigest
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号