hashilb模塊(加密算法)

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()) #不支持中文

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章