p3.0 ,sha和md5加密都集成到hashlib模块中
# coding=utf-8 # Author: RyAn Bi import hashlib #支持加密,sha和md5 m = hashlib.md5() m.update(b"hello") print(m.hexdigest()) m.update(b"It's me") #等同于m2.update(b"helloIt's me"),是前两个的结合 print(m.hexdigest()) m.update(b"it's been a long time since we spoken") print(m.hexdigest()) m2 =hashlib.md5() m2.update(b"helloIt's me") print(m2.hexdigest()) s2 = hashlib.sha1() s2.update(b"helloIt's me") print(s2.hexdigest()) import hmac #消息加密,速度比较快 h=hmac.new("天王盖地虎".encode(encoding='utf-8'),"你是250".encode(encoding='utf-8')) #前面是key,后面是消息,中文必须要encode print(h.digest()) print(h.hexdigest())