/// <summary> /// 加密 Des密钥 /// </summary> /// <param name="original"></param> /// <returns></returns> public byte[] MakeMD5(byte[] original) { MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider(); byte[] keyhash = hashmd5.ComputeHash(original); hashmd5 = null; return keyhash; } /// <summary> /// 加密 穿入密钥 默认zkl /// </summary> /// <param name="original"></param> /// <param name="key"></param> /// <returns></returns> public string Encrypt(string original, string key) { byte[] buff = System.Text.Encoding.Default.GetBytes(original); byte[] kb = System.Text.Encoding.Default.GetBytes(key); TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); des.Key = MakeMD5(kb); des.Mode = CipherMode.ECB; byte[] res = des.CreateEncryptor().TransformFinalBlock(buff, 0, buff.Length); return Convert.ToBase64String(res); } /// <summary> /// 解密 默认密钥 /// </summary> /// <param name="original"></param> /// <returns></returns> public string Decrypt(string original) { byte[] source = Convert.FromBase64String(original);//原文 byte[] key = System.Text.Encoding.Default.GetBytes("zkl");//密钥 TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); des.Key = MakeMD5(key); des.Mode = CipherMode.ECB; byte[] pass= des.CreateDecryptor().TransformFinalBlock(source, 0, source.Length); return Encoding.Default.GetString(pass); }