编程语言
首页 > 编程语言> > PHP实现JAVA的md5算法,php验签对接java

PHP实现JAVA的md5算法,php验签对接java

作者:互联网

/**
     * 16进制转string拼接
     * @param array $bytes [description]
     * @return   [type]                          [description]
     * @author   Lerko
     * @dateTime 2018-01-25T10:18:31+0800
     */
    public function encodeHexString(array $bytes)
    {
        $LOWER   = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
        $length  = count($bytes);
        $charArr = [];
        foreach ($bytes as $value) {
            $value     = intval($value);
            $charArr[] = $LOWER[$this->uright(0xF0 & $value, 4)];
            $charArr[] = $LOWER[0x0F & $value];
        }
        return implode("", $charArr);
    }

    /** php 无符号右移 */
    public function uright($a, $n)
    {
        $c = 2147483647 >> ($n - 1);
        return $c & ($a >> $n);
    }

    /**
     * 模拟DigestUtils.md5
     * @param    [string]                   $string 加密字符
     * @return   [array]                           加密之后的byte数组
     * @author   Lerko
     * @dateTime 2018-01-25T09:28:33+0800
     */
    public function md5Hex($string)
    {
        return unpack("c*", md5($string, true));
    }

  使用方法

$md5 = $this->encodeHexString($this->md5Hex($sign_str))

  

标签:return,string,bytes,value,验签,JAVA,charArr,php,md5
来源: https://www.cnblogs.com/qqkk/p/16543310.html