import hashlib hash = hashlib.md5([bytes('SALT_STRING', encoding='utf-8’)]) #SALT_STRING :加盐 hash.update(bytes('STRING', encoding='utf-8’)) #STRING :要加密的字符串
r = hash.hexdigest() #结果
import hmac h = hmac.new(KEY) #KEY,必写参数, 为bytes类型
h.update(MESSAGE) #MESSAGE 为bytes类型
result = h.hexdigest() 例: h = hmac.new(b'key')
h.update(b'message')
result = h.hexdigest() 结果:'4e4748e62b463521f6775fbf921234b5'