md5加密(正常的md5,加盐,动态加盐)
import hashlib md5 = hashlib.md5() md5.update(b‘alex3714‘) print(md5.hexdigest())
应用于密码的密文存储,文件的一致性校验
import hashlib md5 = hashlib.md5() md5.update(b‘alex3714‘) ret = md5.hexdigest() md =hashlib.md5() md.update(b‘alex‘) md.update(b‘3714‘) res = md.hexdigest() if ret == res: print(‘结果相同‘)
加盐
import hashlib md5 = hashlib.md5() md5.update(b‘alex3714‘) ret = md5.hexdigest() print(ret) md = hashlib.md5(bytes(‘salt‘,encoding=‘utf-8‘)) md.update(b‘alex3714‘) print(md.hexdigest())
bytes,将字符串转化为字节
t = bytes(‘salt‘,encoding=‘utf-8‘) print(t,type(t)
sha1加密
import hashlib sha1 = hashlib.sha1() sha1.update(b‘how to use sha1 in ‘) sha1.update(b‘python hashlib?‘) print(sha1.hexdigest())
原文地址:https://www.cnblogs.com/weidaijie/p/10327774.html
时间: 2024-10-09 12:08:21