1. Encryption Method 1/*** // <summary>
2 // Encryption Method
3 /// </Summary>
4 /// <Param name = "data"> string to be encrypted </param>
5 // <Param name = "key_64"> key </param>
6 /// <Param name = "iv_64"> key </param>
7 /// <returns> encrypted string </returns>
8 Public String encode (string data, string key_64, string iv_64)
9 {
10 byte [] bykey = system. Text. asciiencoding. ASCII. getbytes (key_64 );
11 byte [] byiv = system. Text. asciiencoding. ASCII. getbytes (iv_64 );
12
13 descryptoserviceprovider cryptoprovider = new descryptoserviceprovider ();
14 int I = cryptoprovider. keysize;
15 memorystream MS = new memorystream ();
16 cryptostream CST = new cryptostream (MS, cryptoprovider. createencryptor (bykey, byiv), cryptostreammode. Write );
17
18 streamwriter Sw = new streamwriter (Cst );
19 Sw. Write (data );
20 Sw. Flush ();
21 Cst. flushfinalblock ();
22 Sw. Flush ();
23 return convert. tobase64string (Ms. getbuffer (), 0, (INT) ms. Length );
24
25}
2. Decryption Method
1/** // <summary>
2 // Decryption Method
3 /// </Summary>
4 /// <Param name = "data"> string to be decrypted </param>
5 // <Param name = "key_64"> key </param>
6 /// <Param name = "iv_64"> key </param>
7 // <returns> decrypted string </returns>
8 Public String decode (string data, string key_64, string iv_64)
9 {
10 byte [] bykey = system. Text. asciiencoding. ASCII. getbytes (key_64 );
11 byte [] byiv = system. Text. asciiencoding. ASCII. getbytes (iv_64 );
12
13 byte [] byenc;
14 try
15 {
16 byenc = convert. frombase64string (data );
17}
18 catch
19 {
20 return NULL;
21}
22
23 descryptoserviceprovider cryptoprovider = new descryptoserviceprovider ();
24 memorystream MS = new memorystream (byenc );
25 cryptostream CST = new cryptostream (MS, cryptoprovider. createdecryptor (bykey, byiv), cryptostreammode. Read );
26 streamreader sr = new streamreader (Cst );
27 return Sr. readtoend ();
28}
3. Note: The two keys must be the same during encryption and decryption, that is, the four keys must be the same, for example, 1 result = encode (result, "vavicapp", "vavicapp ");
2
3 connstring = decode (connstring, "vavicapp", "vavicapp ");
4. Reference 1 using system. Security;
2 using system. Security. cryptography;