Home  >  Article  >  Backend Development  >  Signature algorithm for encryption between php data (code)

Signature algorithm for encryption between php data (code)

不言
不言Original
2018-08-17 17:19:202055browse

What this article brings to you is about the signature algorithm (code) for encrypting data in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

    /**
     * 签名生成算法
     * @param  array  $params API调用的请求参数集合的关联数组,不包含sign参数
     * @param  string $secret 签名的密钥即获取access token时返回的session secret
     * @return string 返回参数签名值
     */
    private function getSignature($params) {
        $secret = $this->secretKey;        $str = '';  //待签名字符串
        //先将参数以其参数名的字典序升序进行排序
        ksort($params);        //遍历排序后的参数数组中的每一个key/value对
        foreach ($params as $k => $v) {            //为key/value对生成一个key=value格式的字符串,并拼接到待签名字符串后面
            $str .= $k . $v;
        }        //将签名密钥拼接到签名字符串最后面
        $str .= $secret;        //通过md5算法为签名字符串生成一个md5签名,该签名就是我们要追加的sign参数值
        return md5($str);
    }

Among them

this->secretKey; can be two program conventions Good encrypted characters

Related recommendations:

PHP RSA2 signature algorithm

MD5 combined with RSA to achieve signature in PHP Example analysis of algorithm

The above is the detailed content of Signature algorithm for encryption between php data (code). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn