md5关于加密

# 导入hashlib模块
import hashlib

# 获取MD5对象
# 不加盐操作
# md5 = hashlib.md5()

# 加盐操作
md5 = hashlib.md5('wenwe1i'.encode("utf8"))
# 获取需要加密的字段
md5.update('how to use md5 in python hashlib?'.encode("utf8"))
print(md5.hexdigest())
class Md5(object):
    def __init__(self, salt, content):
        self.salt = salt
        self.content = content

    def encryption(self):
        import hashlib
        md5 = hashlib.md5(self.salt.encode("utf8"))
        md5.update(self.content.encode("utf8"))
        ret = md5.hexdigest()
        return ret

ret = Md5('wenwe1i', 'how to use md5 in python hashlib?')
ret.encryption()

 

posted @ 2019-11-03 09:24  Mr_Riven  阅读(112)  评论(0编辑  收藏  举报