public class EncryptTools ...{ 加密函数#region 加密函数 /** <summary> /// md5加密 /// </summary> /// <param name="pass">原始密码</param> /// <returns></returns> public static string Encryptmd5(string pass) ...{ return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pass, "md5"); } /** <summary> /// sha1加密 /// </summary> /// <param name="pass">原始密码</param> /// <returns></returns> public static string Encryptsha1(string pass) ...{ return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pass, "sha1"); } /** <summary> /// 对密码进行des加密 /// </summary> /// <param name="password"></param> /// <returns></returns> public static string GetDesEncrypt(string oriString) ...{ //实例化des加密算法的对象 DESCryptoServiceProvider aa = new DESCryptoServiceProvider(); aa.Key = ASCIIEncoding.ASCII.GetBytes("hanzz+#"); aa.IV = ASCIIEncoding.ASCII.GetBytes("hanzz+#"); //得到一个加密对象 ICryptoTransform bb = aa.CreateEncryptor(); byte[] b = Encoding.UTF8.GetBytes(oriString); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, bb, CryptoStreamMode.Write); cs.Write(b, 0, b.Length); cs.FlushFinalBlock(); return Convert.ToBase64String(ms.ToArray()); } /** <summary> /// 对密码进行des解密 /// </summary> /// <param name="password"></param> /// <returns></returns> public static string GetDesDecrypt(string oriString) ...{ //实例化des加密算法的对象 DESCryptoServiceProvider aa = new DESCryptoServiceProvider(); aa.Key = ASCIIEncoding.ASCII.GetBytes("hanzz+#"); aa.IV = ASCIIEncoding.ASCII.GetBytes("hanzz+#"); //生成解密算法 ICryptoTransform bb = aa.CreateDecryptor(); byte[] b1 = new byte[oriString.Length]; //转换转换后的值 b1 = Convert.FromBase64String(oriString); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, bb, CryptoStreamMode.Write); cs.Write(b1, 0, b1.Length); cs.FlushFinalBlock(); Encoding ed = new UTF8Encoding(); return ed.GetString(ms.ToArray()); } #endregion }