1. 程式人生 > >hashilb模塊(加密算法)

hashilb模塊(加密算法)

字節 md5 mac date 加密 code you dig update

import hashlib
#
m=hashlib.md5()
m.update(b"hello")
print(m.hexdigest())#以16進制格式hash
print(m.digest()) #以2進制格式hash
m.update(b"It‘s me") #hello+it‘s me
print(m.hexdigest())
m.update(b"go to the school")
print(m.hexdigest())

m2=hashlib.md5()
m2.update("helloIt‘s me天王蓋地虎".encode(encoding="UTF-8")) #encode成字節模式(bytes)

print(m2.hexdigest())

s2=hashlib.sha1()
s2.update(b"helloIt‘s me")
print(s2.hexdigest())

import hmac

h=hmac.new(b"12345","you are 250天王".encode(encoding="UTF-8"))
print(h.digest()) #不支持中文(需要encode)
print(h.hexdigest()) #不支持中文

hashilb模塊(加密算法)