1.首先需要准备待计算的原始消息message,随机key,哈希算法,这里采用MD5,使用hmac的代码如下:
import hmac
message = b'hello world!'
key = b'secret'
h = hmac.new(key,message,digestmod='MD5')
print(h.hexdigest())
运行结果:
"C:\Program Files\Python36\python.exe" C:/Users/Administrator/PycharmProjects/Python全网练习/常用内置模块.py
0a0461e10e89506d7c31a145663bed93
Process finished with exit code 0