hashlib 加密
import hashlib
msg = "msg"
print(hashlib.md5(msg).hexdigest())
print(hashlib.sha1(msg).hexdigest())
print(hashlib.sha224(msg).hexdigest())
print(hashlib.sha256(msg).hexdigest())
print(hashlib.sha384(msg).hexdigest())
print(hashlib.sha512(msg).hexdigest())
hmac 加密
有些加密算法需要有一个key 这时候就用到 hmac
用key sha256加密 msg, base64编码
import hashlib
import hmac
import base64
key = b'key'
msg = 'msg'
signature = hmac.new(key, msg.encode('utf-8'), digestmod=hashlib.sha256).digest()
print(base64.b64encode(signature))