如何在php中创建hmac md5?

如何在php中创建hmac md5?,php,Php,我在payU信用卡系统工作。但我没办法。 payU告诉我必须创建hmac md5哈希 我的秘钥是:3~9#[X4^660?ak+]h6%T 我想转换为HMAC_MD5散列:8GEMISEPE6208617192012-12-15:58:476Deneme117Deneme202103NET112242103TRY2107Antalya7Antalya2TR8CCVISAMC2,3,7,10,12 php代码是什么?您可以使用以下函数轻松完成此操作: $input = 'foo'; $output

我在payU信用卡系统工作。但我没办法。 payU告诉我必须创建hmac md5哈希

我的秘钥是:3~9#[X4^660?ak+]h6%T 我想转换为HMAC_MD5散列:8GEMISEPE6208617192012-12-15:58:476Deneme117Deneme202103NET112242103TRY2107Antalya7Antalya2TR8CCVISAMC2,3,7,10,12


php代码是什么?

您可以使用以下函数轻松完成此操作:

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

其中,
$secretKey
包含密钥的字符串表示形式。

此php函数类适用于我:

   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);

关于“秘密钥匙”的事情通常是你保守秘密;)我希望你能采取必要的措施,避免这个问题成为你应用程序的安全漏洞!到目前为止你试过什么吗?那对我不起作用。他们使用的公式与PHP哈希_hmac转换不同。。我想知道为什么。。。