The encryption and decryption code is as follows:
1 /// <summary> 2 /// encrypted string: returns the encrypted string 3 // </Summary> 4 public static string encrypt (string value, string key) based on the input string and key) 5 {6 try 7 {8 Key + = "[email protected] # $ % ^ & * ()"; 9 byte [] bytecrypt = {0x10, 0x29, 38, 0x47, 0x56}; 10 byte [] bytekey = system. text. encoding. utf8.getbytes (key. substring (0, 10); 11 descryptoserviceprovider des = new descryptoserviceprovider (); 12 byte [] inputbytearray = system. text. encoding. utf8.getbytes (value); 13 memorystream MS = new memorystream (); 14 cryptostream cs = new cryptostream (MS, Des. createencryptor (bytekey, bytecrypt), cryptostreammode. write); 15 CS. write (inputbytearray, 0, inputbytearray. length); 16 CS. flushfinalblock (); 17 return convert. tobase64string (Ms. toarray (); 18} 19 catch (exception ex) 20 {21 throw ex; 22} 23} 24 25 // <summary> 26 // encrypted string: the encrypted string 27 // </Summary> 28 public static string encrypt (string value) 29 {30 return encrypt (value, String. empty); 31} 32 33 // <summary> 34 // decrypt the string: return the decrypted string 35 // </Summary> 36 public static string decrypt (string value, string key) based on the input string and key) 37 {38 try39 {40 key + = "[email protected] # $ % ^ & * ()"; 41 byte [] bytecrypt = {0x10, 0x29, 38, 0x47, 0x56}; 42 byte [] bytekey = system. text. encoding. utf8.getbytes (key. substring (0, 10); 43 descryptoserviceprovider des = new descryptoserviceprovider (); 44 byte [] inputbytearray = convert. frombase64string (value); 45 memorystream MS = new memorystream (); 46 cryptostream cs = new cryptostream (MS, Des. createdecryptor (bytekey, bytecrypt), cryptostreammode. write); 47 CS. write (inputbytearray, 0, inputbytearray. length); 48 CS. flushfinalblock (); 49 system. text. encoding encoding = system. text. encoding. utf8; 50 return encoding. getstring (Ms. toarray (); 51} 52 catch (exception ex) 53 {54 throw ex; 55} 56} 57 58 // <summary> 59 // decrypt the string: return the decrypted string 60 // </Summary> 61 Public static string decrypt (string value) 62 {63 return decrypt (value, String. empty); 64}View code
Encryption and decryption Methods