等同于 .NET 中的 PHP hash_hmac("sha384", $data, $key)

Equivalent from PHP hash_hmac("sha384", $data, $key) in .NET

在 PHP 中,我执行以下步骤:

<?php
  $key="mM8Y28b5R7KFe3Y5";   
  $data="298052380sbEUREinzellizenz Spieler SEN329739test120211572380R-00001003authorization19";
  $hash=hash_hmac("sha384", $data, $key);
  echo $hash;
?>

我得到以下输出:

f34fb28f6462cde18a92ee854d289ba5aed3cfc07d0abb52cfef3b70028e1b38b098ae17514a9121d43d3d6f684eccd8

我尝试在 .NET 中使用:

string data = "298052380sbEUREinzellizenz Spieler SEN329739test120211572380R-00001003authorization19";
      string key = "mM8Y28b5R7KFe3Y5";
      string hash = "";
      using (SHA384 sha384Hash = SHA384.Create())
      {
        byte[] sourceBytes = Encoding.ASCII.GetBytes(data);
        byte[] hashBytes = sha384Hash.ComputeHash(sourceBytes);
        hash = BitConverter.ToString(hashBytes).Replace("-", String.Empty).ToLower();
      }

我得到

77b7eccd4f66b07c66e2c49b83e53bf84dfd4dc67ec60007df4476adfe16d9b0bfdd6e58e9a5008bde4908335d161ef5

我也试过:

var keyByte = Encoding.ASCII.GetBytes(key);
      using (HMACSHA256 sha384Hash = new HMACSHA256(keyByte))
      {
        byte[] sourceBytes = Encoding.ASCII.GetBytes(data);
        byte[] hashBytes = sha384Hash.ComputeHash(sourceBytes);
        hash2 = BitConverter.ToString(hashBytes).Replace("-", String.Empty).ToLower();
      }

hash2 是

ceaabe254e19d77940ac3edfdf2fa3d1de424d569136e8deb770aa81be5cb24a

我不明白其中的区别。我已经检查了编码,但我看不出有什么不同。

我做错了什么?

使用第二个示例,但使用

using (HMACSHA384 sha384Hash = new HMACSHA384(Encoding.ASCII.GetBytes(key)))