MD5加密方法HashPasswordForStoringInConfigFile(string,string)过时问题处理方法

  最近写代码的时候一直有一种很奇怪的感觉,查了一下发现原来是系统中的MD5加密方法报了过时的警告,虽然对系统没有任何影响,但是开发过程中绿色波浪线就像挥之不去的阴影一样。开发人员多多少少都会有点强迫症,因此百度了一下解决办法,接下来把方法贴出来,作为记录以及其他人参考。

  如下图所示,System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile() 这个方法出现了绿色波浪线,提示已过时。

  

   解决办法如下:

        System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
        user.Password = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(passwordBox.Text.Trim()))).Replace("-", null);

  当然别忘记了添加引用:

    using System;
    using System.Text;

  调试一下,能看到前后两种方法加密后的MD5码是一致的。

  

   这样子就可以解决 HashPasswordForStoringInConfigFile 方法报“已过时“的问题了。

原文地址:https://www.cnblogs.com/kaizishu/p/11598103.html