如何在ASP.NET MVC中生成加密哈希?

qua*_*els 6 encryption asp.net-mvc

我正在寻找创建自定义成员登录系统(用于学习),我无法找出C#命令来生成加密的哈希.

是否需要导入某个命名空间或类似的东西?

Gre*_*ire 18

使用命名空间System.Security.Cryptography:

MD5 md5 = new MD5CryptoServiceProvider();
Byte[] originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword);
Byte[]  encodedBytes = md5.ComputeHash(originalBytes);

return BitConverter.ToString(encodedBytes);
Run Code Online (Sandbox Code Playgroud)

FormsAuthentication.HashPasswordForStoringInConfigFile方法

  • 很好...我只需要使用System.Text,这非常有效!TY (2认同)