Encryption
public string Desencrypt (string strText, String strencrkey) { byte[] bykey=null; Byte[] iv= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF}; Try { Bykey = System.Text.Encoding.UTF8.GetBytes (strencrkey.substring (0,8)); DESCryptoServiceProvider des = new DESCryptoServiceProvider (); Byte[] Inputbytearray =system.text.encoding.utf8.getbytes (strText); MemoryStream ms = new MemoryStream (); CryptoStream cs = new CryptoStream (MS, Des. CreateEncryptor (Bykey, IV), cryptostreammode.write); Cs. Write (Inputbytearray, 0, inputbytearray.length); Cs. FlushFinalBlock (); Return convert.tobase64string (Ms. ToArray ()); } catch (System.Exception error) { MessageBox.Show (Error). Message); Return "error:" +error. Message+ "/R"; } }
Decrypt
public string Desdecrypt (String strtext,string sdecrkey) { byte[] bykey = null; Byte[] iv= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF}; byte[] Inputbytearray = new Byte[strtext.length]; Try { Bykey = System.Text.Encoding.UTF8.GetBytes (sdecrkey.substring (0,8)); DESCryptoServiceProvider des = new DESCryptoServiceProvider (); Inputbytearray = convert.frombase64string (strText); MemoryStream ms = new MemoryStream (); CryptoStream cs = new CryptoStream (MS, Des. CreateDecryptor (Bykey, IV), cryptostreammode.write); Cs. Write (Inputbytearray, 0, inputbytearray.length); Cs. FlushFinalBlock (); System.Text.Encoding Encoding = new System.Text.UTF8Encoding (); return encoding. GetString (Ms. ToArray ()); } catch (System.Exception error) { MessageBox.Show (Error). Message); Return "error:" +error. Message+ "/R"; } }