c# - HMACSHA512 构造函数和工厂之间的区别

标签 c# cryptography

为什么这会返回 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/

相关文章:

c# - 如何在C#中使用公钥和私钥加密技术

c# - 如何获取资源中的所有图像列表?

cryptography - 将 .pem 公钥和私钥导入 JKS keystore

ruby - 如何在 Ruby 中使用 PKI(公钥/私钥)加密?

c# - 在 C#/WPF 中加速 L-System 渲染器

c# - 使用 libsodium-net 时,我不需要生成和存储盐吗?

java - 错误的 AES 加密

c# - 单色触摸 : Draggable MKAnnotationView

c# - 在 Razor 中声明变量

c# - 使用 BookSleeve 的 ConnectionUtils.Connect() 将 SignalR 与 Redis 消息总线故障转移结合使用