研究了一下OSS的Policy如何签名
以下是Python的Sample代码
#coding=utf8
import md5
import hashlib
import base64
import hmac
def convert_base64(input):
return base64.b64encode(input)
def get_sign_policy(key, policy):
return base64.b64encode(hmac.new(key, policy, hashlib.sha1).digest())
policy='''
{"expiration":"2015-01-27T10:56:19Z","conditions":[["content-length-range", 0, 1048576]]}
'''
policy="{\"expiration\":\"2015-01-27T10:56:19Z\",\"conditions\":[[\"content-length-range\", 0, 1048576]]}"
print "policy: ", policy
print "policy length: ", len(policy)
secret_access_key = "test"
print "secret_access_key: ", secret_access_key
base64policy = convert_base64(policy)
print "base64policy: ", base64policy
signature = get_sign_policy(secret_access_key, base64policy)
print "signature_of_policy: ", signature
运行的结果:
policy: {"expiration":"2015-01-27T10:56:19Z","conditions":[["content-length-range", 0, 1048576]]}
policy length: 89
secret_access_key: test
base64policy: eyJleHBpcmF0aW9uIjoiMjAxNS0wMS0yN1QxMDo1NjoxOVoiLCJjb25kaXRpb25zIjpbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDAsIDEwNDg1NzZdXX0=
signature_of_policy: XRiWSZLSQPQGG+f3GPYLYMeFjr0=
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。