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 hmach = 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'