【问题标题】:PHP hash_hmac Can't get the same result as vb.net result HMACSHAPHP hash_hmac 无法得到与 vb.net 结果 HMACSHA 相同的结果
【发布时间】:2016-09-21 08:45:29
【问题描述】:

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

PHP:

$ha1='RHBNow';

$ha2=7090982.885183;

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

$urlSafeSignature = urlencode($binarySignature);

结果:

PS7%2FPqt95CtEEGeNsNOV1y%2FEaQ4%3D

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

【问题讨论】:

    标签: php .net vb.net


    【解决方案1】:

    请尝试以下方法:

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

    谢谢。

    【讨论】:

      猜你喜欢
      • 2020-12-10
      • 1970-01-01
      • 2022-05-13
      • 2020-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多