using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Security.Cryptography; namespace BLL { public class md5Manger { #region MD5加密 public static string Md5Encrypt(string strSource) { byte[] bytIn = System.Text.Encoding.Default.GetBytes(strSource); byte[] iv = { 102, 16, 93, 156, 78, 4, 218, 32 }; byte[] key = { 55, 103, 246, 79, 36, 99, 167, 3 }; DESCryptoServiceProvider mobjCryptoService = new DESCryptoServiceProvider(); mobjCryptoService.Key = iv; mobjCryptoService.IV = key; ICryptoTransform encrypto = mobjCryptoService.CreateEncryptor(); System.IO.MemoryStream ms = new System.IO.MemoryStream(); CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write); cs.Write(bytIn, 0, bytIn.Length); cs.FlushFinalBlock(); return System.Convert.ToBase64String(ms.ToArray()); } #endregion #region MD5解密 public static string Md5Decrypt(string Source) { byte[] bytIn = System.Convert.FromBase64String(Source); byte[] iv = { 102, 16, 93, 156, 78, 4, 218, 32 }; byte[] key = { 55, 103, 246, 79, 36, 99, 167, 3 }; DESCryptoServiceProvider mobjCryptoService = new DESCryptoServiceProvider(); mobjCryptoService.Key = iv; mobjCryptoService.IV = key; System.IO.MemoryStream ms = new System.IO.MemoryStream(bytIn, 0, bytIn.Length); ICryptoTransform encrypto = mobjCryptoService.CreateDecryptor(); CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Read); StreamReader strd = new StreamReader(cs, Encoding.Default); return strd.ReadToEnd(); } #endregion } }