C# ';哈希算法&x27;不包含';创建';
我陷入了这样的境地 我曾经在我的MVC 5应用程序中使用此功能:C# ';哈希算法&x27;不包含';创建';,c#,encryption,asp.net-core,password-encryption,C#,Encryption,Asp.net Core,Password Encryption,我陷入了这样的境地 我曾经在我的MVC 5应用程序中使用此功能: public virtual string CreateHash(byte[] data, string hashAlgorithm = "SHA1") { if (String.IsNullOrEmpty(hashAlgorithm)) hashAlgorithm = "SHA1"; var algorithm = HashAlgorithm.Create(hashAlgorithm);
public virtual string CreateHash(byte[] data, string hashAlgorithm = "SHA1")
{
if (String.IsNullOrEmpty(hashAlgorithm))
hashAlgorithm = "SHA1";
var algorithm = HashAlgorithm.Create(hashAlgorithm);
var hashByteArray = algorithm.ComputeHash(data);
return BitConverter.ToString(hashByteArray).Replace("-", "");
}
现在我正在ASP.NET Core中创建一个应用程序。我发现了错误
同样,对于RNGCryptoServiceProvider()
函数,也存在同样的问题。但是我使用了RandomNumberGenerator()
。但我找不到任何解决办法
非常感谢您的帮助。记录的错误将不会被修复
解决办法是:
public static HashAlgorithm Create(String hashAlgorithm) {
return (HashAlgorithm) CryptoConfig.CreateFromName(hashAlgorithm);
}
记录的错误,将不会被修复
解决办法是:
public static HashAlgorithm Create(String hashAlgorithm) {
return (HashAlgorithm) CryptoConfig.CreateFromName(hashAlgorithm);
}
您可以使用
SHA1.Create()
,来复制原始的HashAlgorithm.Create()
您必须编写自己的映射字典,从字符串到要调用的静态工厂方法。我尝试使用var algorithm=SHA1.Create()代码>并且工作正常。。。泰姆!但是如果我需要选择一个不同的算法,可以吗?你可以使用SHA1.Create()
,来复制原始的HashAlgorithm.Create()
你必须写下你自己的从字符串到静态工厂方法的映射字典来调用代码>并且工作正常。。。泰姆!但是如果我需要选择一个不同的算法,有可能吗?