using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace Common { /// <summary> /// 采用 3DES 加解密方式。 /// </summary> public class EncryptAndDecrypte { static string strKey = "fdbc4y6hdhKlf4M3mjgGrMC3PbryXrxw"; static string strIV = "RfnMfrpec48="; /// <summary> /// 默认加密字符串。 /// </summary> /// <param name="ConnString"></param> /// <returns></returns> public static string EncryptString(string encryptString) { if (string.IsNullOrWhiteSpace(encryptString)) return encryptString; return Convert.ToBase64String(EncryptAndDecrypte.EncryptString( encryptString, Convert.FromBase64String(strKey), Convert.FromBase64String(strIV) ) ); } /// <summary> /// 默认解密字符串 /// </summary> /// <param name="EncryptedConnectionString"></param> /// <returns></returns> public static string DecrypteString(string EncryptedConnectionString) { if (string.IsNullOrWhiteSpace(EncryptedConnectionString)) return EncryptedConnectionString; return EncryptAndDecrypte.DecrypteString( Convert.FromBase64String(EncryptedConnectionString), Convert.FromBase64String(strKey), Convert.FromBase64String(strIV) ).TrimEnd('