• 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
  • 相关阅读:
    CentOS下crond定时任务详细介绍
    js随机从数组中取出几个元素
    js复制内容加版权声明代码
    crond不执行原因分析
    2015年最全的移动WEB前端UI框架
    聊聊前端排序的那些事
    Linux下修改Mysql的用户(root)的密码
    SIPp常用脚本之三:UAC
    SIPp常用脚本之二:UAS
    SIPp常用脚本之一:register注册
  • 原文地址:https://www.cnblogs.com/rsapaper/p/11680468.html
Copyright © 2020-2023  润新知