python实现HmacSHA256加密算法

2020-11-24 11:23:08 浏览数 (1)

一.代码

代码语言:javascript复制
from hashlib import sha256
import hmac

def get_sign(data, key):
    key = key.encode('utf-8')
    message = data.encode('utf-8')
    sign = base64.b64encode(hmac.new(key, message, digestmod=sha256).digest())
    sign = str(sign, 'utf-8')
    print(sign)
    return sign

0 人点赞