编程语言
首页 > 编程语言> > Ucloud api signature 生成 (python3)

Ucloud api signature 生成 (python3)

作者:互联网

import hashlib

def _verfy_ac(private_key, params):
    items = sorted(params.items(), key=lambda x: x[0])
    params_data = ""
    for i in items:
        params_data = params_data + i[0] + i[1]
    params_data = params_data + private_key

    sign = hashlib.sha1()
    sign.update(params_data.encode("utf8"))
    signature = sign.hexdigest()

    return signature

s = _verfy_ac("私钥", {
    "Action": "DescribeImage",
    "PublicKey": "公钥",
    "OsType": "Linux",
    "Region": "cn-bj2"
})

print(s)

标签:Ucloud,items,sign,api,params,key,signature,data,python3
来源: https://blog.51cto.com/hequan/2425633