.net 简单实现加密

来源:互联网 发布:有淘宝秒杀软件吗 编辑:程序博客网 时间:2024/05/21 04:24

.net 下有个FormsAuthentication类,其中有个方法如下

//        // 摘要:        //     根据指定的密码和哈希算法生成一个适合于存储在配置文件中的哈希密码。        //        // 参数:        //   password:        //     要进行哈希运算的密码。        //        //   passwordFormat:        //     要使用的哈希算法。passwordFormat 是一个 String,表示 System.Web.Configuration.FormsAuthPasswordFormat        //     枚举值之一。        //        // 返回结果:        //     经过哈希运算的密码。        //        // 异常:        //   System.ArgumentNullException:        //     password 为 null。- 或 -passwordFormat 为 null。        //        //   System.ArgumentException:        //     passwordFormat 不是有效的 System.Web.Configuration.FormsAuthPasswordFormat 值。        public static string HashPasswordForStoringInConfigFile(string password, string passwordFormat);

根据此方法我们可以写个简单的MD5加密

 

/// <summary>         /// MD5加密         /// </summary>         /// <param name="password">要加密的字符串</param>         /// <returns>加密后的字符串</returns>         public static string MD5(string password)         {             return FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");         } 



原创粉丝点击