为什么这会返回 512 位的散列大小......
var text = "Hello World";
var buffer = Encoding.UTF8.GetBytes(text);
var hmac = new System.Security.Cryptography.HMACSHA512();
hmac.Key = GetRandomBits(512);
hmac.ComputeHash(buffer);
Assert.That(hmac.HashSize, Is.EqualTo(512));
...这是一个 160 位的散列大小?
var text = "Hello World";
var buffer = Encoding.UTF8.GetBytes(text);
var hmac = System.Security.Cryptography.HMACSHA512.Create();
hmac.Key = GetRandomBits(512);
hmac.ComputeHash(buffer);
Assert.That(hmac.HashSize, Is.EqualTo(512)); // failure
构造函数和工厂都与 HMACSHA512 相关,所以我假设输出相同。
最佳答案
没有 HMACSHA512.Create()
。您实际上是在调用 HMAC.Create()
(因为该语言允许从派生类型编写对静态方法的调用)
所以你只是得到“一个 HMAC”,它似乎是 HMACSHA1。
关于c# - HMACSHA512 构造函数和工厂之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41303673/