hashilib 加密
MD5
# 防止被篡改
# 防止直接看到明文
# 防止抵赖
import hashlib
m = hashlib.md5()
m.update(b'hello alex')
print(m.hexdigest()) # 16进制md5值
m.update('欢迎来到小猿圈'.encode(('utf-8')))
print(m.digest()) # 消化
print(m.hexdigest()) # 16进制md5值
m2 = hashlib.md5()
m2.update("hello alex欢迎来到小猿圈".encode('utf-8'))
print(m2.hexdigest())
-----------------------------------------------------------------------
a3e3bb5d7611493a6a1200af508fbc0f
b'xaemxf3x85xd5X;ixd7x04Nxbcx88Qx13x15'
ae6df385d5583b69d7044ebc88511315
ae6df385d5583b69d7044ebc88511315
#撞库
#脱库
#加盐
SHA(安全哈希算法)
160位
>>> import hashlib
>>> m = hashlib.md5(b'alex')
>>> m.hexdigest()
'534b44a19bf18d20b71ecc4eb77c572f'
>>>
>>> s1 = hashlib.sha1(b'alex')
>>> s1.hexdigest()
'60c6d277a8bd81de7fdde19201bf9c58a3df08f4'
>>> s2 = hashlib.sha256()
>>> s2.update(b'alex')
>>> s2.hexdigest()
'4135aa9dc1b842a653dea846903ddb95bfb8c5a10c504a7fa16e10bc31d1fdf0'