Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

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

 Share


KaiWn

Recommended Posts

/**
     * 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))

 

Link to post
Link to comment
Share on other sites

 Share

discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    ×
    ×
    • Create New...