3Des implements three DES encryption algorithms for each data block, which is a safer form of DES. 3DES is safer than the original DES. It's all clear. The following is the source code for encryption and decryption. ECB mode. 1 public class _ 3 DESEncrypt 2 {3 4 public static string Encrypt3DES (string a_strString, string a_strKey) 5 {6 TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider (); 7 DES. key = ASCIIEncoding. ASCII. getBytes (System. web. security. formsAuthentication. hashPasswordForStoringInConfigFile (a_strKey, "md5 "). substring (0, 24); 8 DES. mode = CipherMode. ECB; 9 ICryptoTransform DESEncrypt = DES. createEncryptor (); 10 byte [] Buffer = ASCIIEncoding. ASCII. getBytes (a_strString); 11 return Convert. toBase64String (DESEncrypt. transformFinalBlock (Buffer, 0, Buffer. length); 12} 13 14 public static string Decrypt3DES (string a_strString, string a_strKey) 15 {16 TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider (); 17 DES. key = ASCIIEncoding. ASCII. getBytes (System. web. security. form SAuthentication. hashPasswordForStoringInConfigFile (a_strKey, "md5 "). substring (0, 24); 18 DES. mode = CipherMode. ECB; 19 DES. padding = System. security. cryptography. paddingMode. PKCS7; 20 ICryptoTransform DESDecrypt = DES. createDecryptor (); 21 string result = ""; 22 try23 {24 byte [] Buffer = Convert. fromBase64String (a_strString); 25 26 result = ASCIIEncoding. ASCII. getString (DESDecrypt. transformFinalBlock (B Uffer, 0, Buffer. length); 27 28 // MemoryStream msDecrypt = new MemoryStream (Buffer); 29 // CryptoStream csDecrypt = new CryptoStream (msDecrypt, 30 // DES. createDecryptor (DES. key, DES. IV), 31 // CryptoStreamMode. read); 32 33 // Create buffer to hold the decrypted data.34 // byte [] fromEncrypt = new byte [Buffer. length]; 35 36 // Read the decrypted data out of the crypto stream37 // and place it The temporary buffer.38 // csDecrypt. read (fromEncrypt, 0, fromEncrypt. length); 39 // result = System. text. encoding. default. getString (fromEncrypt); 40} 41 catch (Exception e) 42 {43} 44 return result; in 45 46} 47}, encryption and decryption are implemented based on DES. The difference is that the Key value of 3Des is 24 bits, and DES is 8 bits.