将C#中的HMAC Hash转换为PHP

时间:2017-08-15 22:46:07

标签: c# php

所以我正在努力解决这个问题。我试图在PHP中编写一个函数,它将在C#中有效地执行与此方法相同的操作:

private string CalculateSignature(string apiKey, string secretKey, long timeStamp)
    {
        // Generate the hash
        System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
        HMACMD5 hmac = new HMACMD5(encoding.GetBytes(secretKey));
        byte[] hash = hmac.ComputeHash(encoding.GetBytes(apiKey + timeStamp));

        // Convert hash to digital signature string
        string signature = BitConverter.ToString(hash).Replace("-", "").ToLower();
        return signature;
    }

到目前为止,这就是我的全部内容:

function calcSignature($apiKey, $secrekKey, $timeStamp)
{
    $retval = hash_hmac('md5', $secrekKey, $apiKey . $timeStamp, false);

    return $retval;
}

非常感谢任何帮助,谢谢!

0 个答案:

没有答案