• sign


        def getSignStr(secretKey, signStr):
    '''
    https://cloud.tencent.com/document/product/570/13939
    $secretKey = 'pxPgRWDbCy86ZYyqBTDk7WmeRZSmPco0';
    $srcStr = 'GETdsa.api.qcloud.com/v2/index.php?Action=GetDsaHostList&Nonce=48059&SecretId=AKIDT8G5AsY1D3MChWooNq1rFSw1fyBVCX9D&SignatureMethod=HmacSHA256&Timestamp=1502197934&length=10&offset=0';
    $signStr = base64_encode(hash_hmac('sha256', $srcStr, $secretKey, true));
    echo $signStr;
    oC20lImZgsEZYZqHYQnbvBxEkIFUxgoDhE3GkQA8Ax8=


    https://www.php.net/manual/en/function.hash-hmac.php
    hash_hmac ( string $algo , string $data , string $key [, bool $raw_output = FALSE ] ) : string
    algo
    Name of selected hashing algorithm (i.e. "md5", "sha256", "haval160,4", etc..) See hash_hmac_algos() for a list of supported algorithms.

    data
    Message to be hashed.

    key
    Shared secret key used for generating the HMAC variant of the message digest.

    raw_output
    When set to TRUE, outputs raw binary data. FALSE outputs lowercase hexits.


    # https://github.com/TencentCloud/tencentcloud-sdk-python/blob/c53791afe6403c57a0cacbf9cb1512870c070ec4/tencentcloud/common/sign.py

    :param strList:
    :return:
    '''
    import hmac
    import hashlib
    import urllib.parse
    import binascii

    signStr = bytes(signStr, 'utf-8')
    secretKey = bytes(secretKey, 'utf-8')
    digestmod = hashlib.sha256
    hashed = hmac.new(secretKey, signStr, digestmod)
    base64 = binascii.b2a_base64(hashed.digest())[:-1]
    base64 = base64.decode()
    ret = urllib.parse.quote(base64, safe='')
    return ret
  • 相关阅读:
    matplotlib直方图绘图并且标注数字
    爬虫最基础知识串行和异步进阶代码
    卡方检验
    德国VoIP 系统中发现秘密后门
    python 处理字典键值合并
    python 读取json大文件
    上下文管理器的使用
    服务端高并发分布式架构
    上下文管理器连接数据库示例
    上下文管理器
  • 原文地址:https://www.cnblogs.com/rsapaper/p/11680468.html
Copyright © 2020-2023  润新知