MSDN有一个表,其中包含对该方法有效的值。但是 SHA1CryptoServiceProvider
和 SHA1Cng
成功了,即使它们不在列表中也是如此。
即
HashAlgorithm.Create("System.Security.Cryptography.SHA1Cng");
文档不完整,还是我误解了它们?
最佳答案
我不相信你有任何误解。该文档似乎不仅不完整,而且不正确。
不仅有其他值返回哈希算法的实例,而且它使用的查找表也会导致它抛出异常而不是返回 null
。
例如,下面的每一个都会抛出一个InvalidCastException
,但是文档明确指出它应该返回null
。
System.Security.Cryptography.HashAlgorithm.Create("1.2.840.113549.1.9.3");
System.Security.Cryptography.HashAlgorithm.Create("Triple DES");
System.Security.Cryptography.HashAlgorithm.Create("X509Chain");
关于c# - Hash Algorithm 的 "Create"方法的文档是否有缺陷?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31816785/