老方法代码

var result=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("要加密的字符串", "MD5");

 

新的方法代码

using System.Security.Cryptography; 
string strEncrypt=string.Empty;
using (var md5 = MD5.Create())
                {
                    var result = md5.ComputeHash(Encoding.UTF8.GetBytes("要加密的字符串"));
                    var strResult = BitConverter.ToString(result);
                    strEncrypt= strResult.Replace("-", "");
                }

 

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