• 解决Flutter跟php中哈希sha1算法签名配对


    之前做iOS使用的是AES+RSA加密,这次flutter使用sha1验签
    php给的文档。php通过hash_hmac方法直接传入两个参数token和数据,token对数据字符串加密获得签名。
    function signature(array $data, $token) { $signStr = ''; ksort($data); foreach ($data as $key=>$val){ if(!is_scalar($val)){ $val = json_encode($val); } $signStr .= $key . $val; } return strtoupper(bin2hex(hash_hmac('sha1', $signStr, $token, true))); }

    flutter中解决 解密出来的结果是103c6e83fa9c75a1f20486f950faaddafd9e3f65 跟php验签成功
    const token = "qmbn6jmgxidclbarne9srczb92yz53pe";
        Map parameters = {
          "auth_name": "qqqqqqq",
          "APP-ID": "123456",
        };
        //获得字典中所有key并排序
        List attrKeys = parameters.keys.toList();
        attrKeys.sort();
        
        //获得字典中数据的字符串
        String parameterStr = '';
        for (var i = 0; i < attrKeys.length; i++) {
          parameterStr += "${attrKeys[i]}${parameters[attrKeys[i]]}";
        }

        var key = utf8.encode(token);
        var bytes = utf8.encode(parameterStr);
        //使用token对字典加密
        var hmacSha1 = Hmac(sha1, key);
        Digest sha1Result = hmacSha1.convert(bytes);
    //转大写字符串
    var sha1ResultStr = sha1Result.toString().toUpperCase();
        print("sha1ResultStr:$sha1ResultStr");

  • 相关阅读:
    php编译错误:jpeglib.h not found.
    php编译错误:Please reinstall the libcurl distribution
    php编译错误:Cannot find OpenSSL's <evp.h>
    php shmop windows 信号量锁
    vsftpd配置
    putty ssh 证书登录及问题
    mysql被收购 用mariadb
    centos 7 php7 yum源
    3dmax 欢迎页卡住
    用python进行服务器的监控
  • 原文地址:https://www.cnblogs.com/xsiOS/p/15580547.html
Copyright © 2020-2023  润新知