Listing 1

using System.Security.Cryptography;
...
private byte[] EncryptMessage(string szPlainText, byte[] baKey, byte[] baIV)
		{
	        
			//Here we create a reference to the 3DES cipher
			SymmetricAlgorithm oTripleDES= TripleDES.Create();

			//Set our Key and Initialization Vector
			oTripleDES.Key = baKey;

			//Set the cipher mode to Chain Block Cipher
			oTripleDES.Mode=CipherMode.CBC;
			oTripleDES.IV = baIV;

			//Create the memory stream and crypto steam used to 
			//encrypt the data.  Notice the CryptoStreamMode.Write.
			//This is used to encrypt data
			MemoryStream sMS= new MemoryStream();
			CryptoStream sCS= new CryptoStream( sMS,
				oTripleDES.CreateEncryptor(), 
				CryptoStreamMode.Write);

			//Take the message to encrypt (in the case
			//szPlainText) and encode that into a byte
			//array for encrypting.
			byte[] baPlainBytes = Encoding.UTF8.GetBytes(szPlainText);
			sCS.Write(baPlainBytes, 0, baPlainBytes.Length);
			sCS.Close();
			byte[] baCipherBytes = sMS.ToArray();
			sMS.Close();
			return baCipherBytes;
		}

		private byte[] DecryptMessage(byte[] baCipherBytes, byte[] baKey, byte[] baIV)
		{
			//Here we create a reference to the 3DES cipher
			SymmetricAlgorithm oTripleDES= TripleDES.Create();

			//Set our Key and Initialization Vector
			oTripleDES.Key = baKey;

			//Set the cipher mode to Chain Block Cipher
			oTripleDES.Mode=CipherMode.CBC;
			oTripleDES.IV = baIV;

			//Create the memory stream and crypto steam used to
			//encrypt the data.  Notice the CryptoStreamMode.Read.
			//This is used to decrypt data
			MemoryStream sMS = new MemoryStream    (baCipherBytes);
			CryptoStream sCS = new CryptoStream( 
				sMS,
				oTripleDES.CreateDecryptor(), 
				CryptoStreamMode.Read);

			//Create a byte array to hold decrypted message
			Byte[] baPlainBytes = new     Byte[baCipherBytes.Length];
			//Decode the steam of encrypted bytes into      plain text again.
			sCS.Read(baPlainBytes, 0, baPlainBytes.Length);
			sCS.Close();
			sMS.Close();

			//Return the decrypted text
			return baPlainBytes;
		}