namespace HW.Utility { using System; using System.Security.Cryptography; using System.Text; public class CryptographyUti { private string _key; public string Decrypt(string strEncrypted) { string str; try { str = Decrypt(strEncrypted, this._key); } catch (Exception exception) { throw exception; } return str; } public static string Decrypt(string strEncrypted, string strKey) { string str3; try { TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider(); MD5CryptoServiceProvider provider2 = new MD5CryptoServiceProvider(); string s = strKey; byte[] buffer = provider2.ComputeHash(Encoding.Unicode.GetBytes(s)); provider2 = null; provider.Key = buffer; provider.Mode = CipherMode.ECB; byte[] inputBuffer = Convert.FromBase64String(strEncrypted); string str2 = Encoding.Unicode.GetString(provider.CreateDecryptor().TransformFinalBlock(inputBuffer, 0, inputBuffer.Length)); provider = null; str3 = str2; } catch (Exception exception) { throw exception; } return str3; } public string Encrypt(string strToEncrypt) { string str; try { str = Encrypt(strToEncrypt, this._key); } catch (Exception exception) { throw exception; } return str; } public static string Encrypt(string strToEncrypt, string strKey) { string str2; try { TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider(); MD5CryptoServiceProvider provider2 = new MD5CryptoServiceProvider(); string s = strKey; byte[] buffer = provider2.ComputeHash(Encoding.Unicode.GetBytes(s)); provider2 = null; provider.Key = buffer; provider.Mode = CipherMode.ECB; byte[] bytes = Encoding.Unicode.GetBytes(strToEncrypt); str2 = Convert.ToBase64String(provider.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length)); } catch (Exception exception) { throw exception; } return str2; } public string Key { set { this._key = value; } } } }