我有以下用Java编写的代码
Mac mac = Mac.getInstance("HmacSHA1");
String secretKey ="sKey";
String content ="Hello";
byte[] secretKeyBArr = secretKey.getBytes();
byte[] contentBArr = content.getBytes();
SecretKeySpec secret_key = new SecretKeySpec(secretKeyBArr,"HmacSHA1");
byte[] secretKeySpecArr = secret_key.getEncoded();
mac.init(secret_key);
byte[] final = mac.doFinal(contentBArr);
Run Code Online (Sandbox Code Playgroud)
我想在C#中做同样的例子.所以,我写了下面的代码
HMACSHA1 hmacsha1 = new HMACSHA1();
string secretKey = "sKey";
string content = "Hello";
byte[] secretKeyBArr = Encoding.UTF8.GetBytes(secretKey);
byte[] contentBArr = Encoding.UTF8.GetBytes(content);
hmacsha1.Key = secretKeyBArr;
byte[] final = hmacsha1.ComputeHash(contentBArr);
Run Code Online (Sandbox Code Playgroud)
最终结果并不相同.secretKeyBArr和contentBArr是字节数组,它们的值在两个示例中都相同.未知的是传递给mac.init()的SecretKeySpec.那么,什么是C#中相同的同类?