【发布时间】:2023-08-25 13:36:01
【问题描述】:
我将 .net webapi 移植到 .net core webapi。 在我使用的旧代码中
Cryptographer.CreateHash("SHA1CryptoServiceProvider", strPass);
为此,我使用了库
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography
但在移植到 .net 核心后,我遇到了问题:
{System.MissingMethodException: Method not found: 'System.AppDomainSetup System.AppDomain.get_SetupInformation()'.
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource.SafeGetCurrentConfigurationFile()
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceFactory.Create()
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet()
at Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.Cryptographer.GetHashProvider(String hashInstance)
at Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.Cryptographer.CreateHash(String hashInstance, String plaintext)
at Social27Bot.DAL.Data.Mappers.Security.EncryptPass(String strPass)
解决办法是什么?
【问题讨论】:
-
因为您使用 SHA41 对字符串进行哈希处理,我觉得这个问题是 Using SHA-1 in .NET Core 的部分重复
-
您的应用中有 appname.config 文件吗?可能与a config file problem 有关
-
不要使用
Microsoft.Practices.EnterpriseLibrary。它是十多年前创建的遗留库,用于处理现在由 .NET 本身处理的场景。它绝对不适用于 Core。 -
此外,SHA1 已经过时,多年来一直被认为是密码散列的危害。它太容易坏了。在任何情况下都不应该使用它,尤其是针对新运行时的代码。同样,密码的安全加密散列已经在 .NET 中通过 Rfc2898DeriveBytes 类提供。
标签: asp.net-core .net-core asp.net-core-2.0