zoukankan      html  css  js  c++  java
  • 阿里云获取签名值

    1.
    
    示例 1. 参数拼接法
    以调用 DescribeRegions 查询地域为例。假设您获得了 AccessKeyID=testid 以及 AccessKeySecret=testsecret,签名流程如下所示:
    
    构造规范化请求字符串。
    http://ecs.aliyuncs.com/?Timestamp=2016-02-23T12:46:24Z&Format=XML&AccessKeyId=testid&Action=DescribeRegions&SignatureMethod=HMAC-SHA1&SignatureNonce=3ee8c1b8-83d3-44af-a94f-4e0ad82fd6cf&Version=2014-05-26&SignatureVersion=1.0
    构造待签名字符串 StringToSign。
    GET&%2F&AccessKeyId%3Dtestid%26Action%3DDescribeRegions%26Format%3DXML%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3D3ee8c1b8-83d3-44af-a94f-4e0ad82fd6cf%26SignatureVersion%3D1.0%26Timestamp%3D2016-02-23T12%253A46%253A24Z%26Version%3D2014-05-26
    计算签名值。因为 AccessKeySecret=testsecret,用于计算的Key为 testsecret&,计算得到的签名值为 OLeaidS1JvxuMvnyHOwuJ+uX5qY=。示例使用的是Java Base64编码方法。
    Signature = Base64( HMAC-SHA1( AccessSecret, UTF-8-Encoding-Of(StringToSign) ) )
    添加 RFC3986 规则编码后的Signature=OLeaidS1JvxuMvnyHOwuJ%2BuX5qY%3D 到 步骤1 的URL中。
    http://ecs.aliyuncs.com/?SignatureVersion=1.0&Action=DescribeRegions&Format=XML&SignatureNonce=3ee8c1b8-83d3
    
    
    python 实现:
    
    # -*- coding:utf-8 -*-
    # !/usr/bin/python
    from hashlib import sha1
    import hmac
    import base64
    #Signature = Base64( HMAC-SHA1( AccessSecret, UTF-8-Encoding-Of(StringToSign) ) )
    #http://ecs.aliyuncs.com/?Timestamp=2016-02-23T12:46:24Z&Format=XML&AccessKeyId=testid&Action=DescribeRegions&SignatureMethod=HMAC-SHA1&SignatureNonce=3ee8c1b8-83d3-44af-a94f-4e0ad82fd6cf&Version=2014-05-26&SignatureVersion=1.0
    #Signature = Base64( HMAC-SHA1( AccessSecret, UTF-8-Encoding-Of(StringToSign) ) )
    #计算签名值。因为 AccessKeySecret=testsecret,用于计算的Key为 testsecret&,计算得到的签名值为 OLeaidS1JvxuMvnyHOwuJ+uX5qY=。示例使用的是Java Base64编码方法。
    #Signature = Base64( HMAC-SHA1( AccessSecret, UTF-8-Encoding-Of(StringToSign) ) )
    a='GET&%2F&AccessKeyId%3Dtestid%26Action%3DDescribeRegions%26Format%3DXML%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3D3ee8c1b8-83d3-44af-a94f-4e0ad82fd6cf%26SignatureVersion%3D1.0%26Timestamp%3D2016-02-23T12%253A46%253A24Z%26Version%3D2014-05-26'
    a=a.encode('utf-8')
    my_sign = hmac.new('testsecret&',a, sha1).digest()
    my_sign = base64.b64encode(my_sign)
    print my_sign
    
    
    C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/aliyun/y1.py
    OLeaidS1JvxuMvnyHOwuJ+uX5qY=
  • 相关阅读:
    动手动脑11.19
    随机产生四则运算,导入导出文件
    JAVA常用的异常处理情况
    动手动脑11.12
    动手动脑11.1
    动手动脑10.21
    动手动脑10.14
    Cygwin install apt-cyg
    php获取request_uri
    linux下sed批量替换文件内容
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348941.html
Copyright © 2011-2022 走看看