
#用于加密的相关操作,3.x里代替了md5模块和sha模块,主要提供sha1,sha224,sha256,sha384,sha512,md5算法
#sha2为主流加密算法,md5加密方式不如sha2
import hashlib
m = hashlib.md5()
m.update(b"hello")
m.update(b"it's me")
print(m.digest())#二进制格式hash
print(m.hexdigest())#16进制格式hash,无论什么加密都用此方法
m.update(b"it's a long time since last time we met..")
print(m.hexdigest()) b = hashlib.md5()
b.update(b"hello")
b.update(b"it's me")
print(b.hexdigest())#只要输入的值是一样的那么加密后的md5对比值也是一样的 #-----------------------------------
c = hashlib.sha512()
c.update(b"hello")
print(c.hexdigest()) #更牛逼的加密方式hmac,它内部对我们创建key和内容再进行处理然后再加密
import hmac
h = hmac.new(b"wohaoshuai")#相当于是key,密钥
h.update(b"hello wohaoshuai")
print(h.hexdigest())