1. 通过 HTTP 请求 Header 发送的签名
算法
Signature = base64(hmac - sha1(VERB + "\n" + CONTENT - MD5 + "\n" + CONTENT - TYPE + "\n" + DATE + "\n" [+ CanonicalizedKssHeaders + "\n"] + CanonicalizedResource, SecreteKey))
示例:
import hashlib import hmac import base64 verb = 'PUT' md5 = 'xxxxx' content_type = 'xxx' date = 'xxxxx' resource = '/xxx' string_to_sgin = verb +'\n' + md5 + '\n' + content_type + '\n' + date_ + '\n' + resource sginature = base64.encodebytes(hmac.new(sk.encode(),string_to_sgin.encode(),hashlib.sha1).digest()).strip().decode()
2. 通过URL QueryString发送的签名
算法
Signature = base64(hmac - sha1(VERB + "\n"
+ "" + "\n"
+ "" + "\n"
+ Expires + "\n"
+ CanonicalizedResource, SecreteKey))
示例:
import hashlib import hmac import base64 string_to_sgin2 = 'GET' + '\n' + '\n' + '\n' + '1607782768' + '\n' + '/' sginature = base64.encodebytes(hmac.new(sk.encode(),string_to_sgin2.encode(),hashlib.sha1).digest()).strip().decode()