擅长:python、mysql、java
<p>这个特性现在是<a href="https://github.com/boto/botocore/pull/735/files" rel="noreferrer">already supported in Botocore</a>,它是<a href="https://github.com/boto/boto3" rel="noreferrer">Boto3, the latest official AWS SDK for Python</a>的底层库。(以下示例需要安装rsa包,但您也可以使用其他rsa包,只需定义自己的“规范化rsa签名者”。)</p>
<p>用法如下:</p>
<pre><code> from botocore.signers import CloudFrontSigner
# First you create a cloudfront signer based on a normalized RSA signer::
import rsa
def rsa_signer(message):
private_key = open('private_key.pem', 'r').read()
return rsa.sign(
message,
rsa.PrivateKey.load_pkcs1(private_key.encode('utf8')),
'SHA-1') # CloudFront requires SHA-1 hash
cf_signer = CloudFrontSigner(key_id, rsa_signer)
# To sign with a canned policy::
signed_url = cf_signer.generate_presigned_url(
url, date_less_than=datetime(2015, 12, 1))
# To sign with a custom policy::
signed_url = cf_signer.generate_presigned_url(url, policy=my_policy)
</code></pre>
<p>免责声明:我是公关的作者</p>