How to create hmac md5 in php?

后端 未结 2 1238
既然无缘
既然无缘 2021-01-03 08:41

I am working with payU credit card systems. But I dont manage. payU tells me that I have to create hmac md5 hashes.

My secret key is : 3~9#[X4^660?ak+]h6%T I want to

相关标签:
2条回答
  • 2021-01-03 09:34

    this php function class worked for me:

       function hmac ($key, $data)
                  {
                  // RFC 2104 HMAC implementation for php.
                  // Creates an md5 HMAC.
                  // Eliminates the need to install mhash to compute a HMAC
                  // Hacked by Lance Rushing
                  $b = 64; // byte length for md5
                  if (strlen($key) > $b) {
                  $key = pack("H*",md5($key));
                  }
                  $key = str_pad($key, $b, chr(0x00));
                  $ipad = str_pad('', $b, chr(0x36));
                  $opad = str_pad('', $b, chr(0x5c));
                  $k_ipad = $key ^ $ipad ;
                  $k_opad = $key ^ $opad;
                  return md5($k_opad . pack("H*",md5($k_ipad . $data)));
                  }
    
    
                $x_fp_hash = hmac($string1,$string2);
    
    0 讨论(0)
  • 2021-01-03 09:39

    You can easily do that using the hash_hmac() function:

    $input = 'foo';
    $output = hash_hmac('md5', $input, $secretKey);
    

    where $secretKey holds a string representation of your key.

    0 讨论(0)
提交回复
热议问题