哈希算法,散列算法,摘要算法——Python笔记

 

Hashlib

它通过一个函数,把任意长度的数据转换为一个长度固定的数据串(通常用16进制的字符串表示)。

import hashlib
md5 = hashlib.md5()
md5.update('how to use md5 in python hashlib?'.encode('utf-8'))
print(md5.hexdigest())



运行结果:

d26a53750bc40b38b65a520292f69306

 

 

hmac

import hmac
message = b'Hello, world!'
key = b'secret'
h = hmac.new(key, message, digestmod='MD5')
print( h.hexdigest())



运行结果:

fa4ee7d173f2d97ee79022d1a7355bcf

猜你喜欢

转载自blog.csdn.net/qq_36230524/article/details/82735341