Using system.sem.text; using system.security.cryptography; using system.io; Namespace des1 {//// /// Testdea's summary description. /// summary> public class des3 {public des3 () {}
/// /// encryption method /// summary> /// plaintext, Unicode encoding param> /// password, base64 encoding param> /// encryption result, base64 encoding returns> public static string encrypt (string strData, string bs64key) {TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider ();
des.Mode = CipherMode.ECB; des.Padding = PaddingMode.PKCS7; des.Key = Convert.FromBase64String (bs64key); byte [] bData = ASCIIEncoding.ASCII.GetBytes (strData); return Convert.ToBase64String (des.CreateEncryptor ( ) .Transformfinalblock (bdata, 0, bdata.length);}
/// ///////// summary> /// plaintext, base64 encoding param> /// password, base64 encoding param> /// decrypting result, Unicode encoding returns> public static string decrypt (string strData, string bs64key) {TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider (); des.Mode = CipherMode.ECB; des .Padding = PaddingMode.PKCS7; des.Key = Convert.FromBase64String (bs64key); byte [] bData = Convert.FromBase64String (strData);. return ASCIIEncoding.ASCII.GetString (des.CreateDecryptor () TransformFinalBlock (bData, 0, bData }}}