Skip to content
欢迎扫码关注公众号

FormsAuthentication.HashPasswordForStoringInConfigFile 方法已弃用

原使用 FormsAuthentication.HashPasswordForStoringInConfigFile 方法实现的 MD5 加密,但是该方法已经过期了。

而且由于需要迁移到 .NET Core,所以干脆改掉了。

原实现代码

csharp
using System.Web.Security;

return FormsAuthentication.HashPasswordForStoringInConfigFile(strData, "MD5").ToUpper();

修改后代码

csharp
using System.Security.Cryptography;

using (var md5 = MD5.Create())
{
    var result = md5.ComputeHash(Encoding.UTF8.GetBytes(strData));
    var strResult = BitConverter.ToString(result);
    return strResult.Replace("-", "").ToUpper();
}

需要注意的是 ComputeHash 中的参数需要使用 UTF8 格式编码才能保持同 FormsAuthentication.HashPasswordForStoringInConfigFile 方法的结果一致。

引用

  1. ASP.NET CORE 中使用 MD5 加密

Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.