编程语言
首页 > 编程语言> > 使用Python 计算KS3 签名,

使用Python 计算KS3 签名,

作者:互联网

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()

 

标签:hashlib,string,KS3,Python,base64,签名,encode,import,hmac
来源: https://www.cnblogs.com/zhangmingda/p/14127215.html