# Python version:3.6.5 import hashlib import urllib from urllib.parse import urlparse params = { "Action": "DescribeUHostInstance", "Region": "cn-bj2", "Limit": 10, 'PublicKey': '[email protected]' } private_key = '46f09bb9fab4f12dfc160dae12273d5332b5debe' def _verfy_ac(private_key, params): """ 参考文章: https://docs.ucloud.cn/UCloudStack/apiguide/overview?id=_13-%e7%ad%be%e5%90%8d%e7%ae%97%e6%b3%95 https://docs.ucloud.cn/api/summary/signature """ # 请求参数串 items=list(params.items()) # 将参数串排序 items.sort() # 拼接 params_data = ""; for key, value in items: params_data = params_data + str(key) + str(value) params_data = params_data + private_key # 生成的Signature值 sign = hashlib.sha1() sign.update(params_data.encode("utf-8")) signature = sign.hexdigest() return signature def a = _verfy_ac(private_key,params) print(a) if a == 'cba5cf5ec4d4233d206b1b54951e3787350a642f': print('sucess')
标签:ucloud,items,private,算法,params,签名,key,data From: https://www.cnblogs.com/suyj/p/17176364.html