PHP hash_hmac无法获得与vb.net结果HMACSHA相同的结果

时间:2016-09-21 08:45:30

标签: php .net vb.net

VB.net代码:

Function HMACSHA(ByVal Key As String, ByVal Value As String)

   Dim objHMAC As New HMACSHA1(Encoding.ASCII.GetBytes(Key))

   HMACSHA_Encrypt = (objHMAC.ComputeHash(Encoding.ASCII.GetBytes(Value)))

End Function

实施例

Key         e.g. “RHBNow”
Value       e.g. “7090982.885183” based on custom hash algorithms
Hash value  e.g. bcf370bcbb6248c4d718ec17e5c6982477744f6a

腓:

$ha1='RHBNow';

$ha2=7090982.885183;

$binarySignature = base64_encode(hash_hmac('sha1',$ha1,$ha2, true));

$urlSafeSignature = urlencode($binarySignature);

结果:

PS7%2FPqt95CtEEGeNsNOV1y%2FEaQ4%3D

无法获得与vb.net结果相同的结果。

1 个答案:

答案 0 :(得分:0)

请尝试以下方法:

<?php
$ha1 = "RHBNow";
$ha2 = "7090982.885183";
echo $hash = hash_hmac('sha1', $ha2, $ha1);
?>

感谢。