public static void Test()
		{
			Console.Out.WriteLine("Begin Example_060.");
			// Create the AES Service
			AESService aes = new AESService();

			string password = "******";
			SecureRandom random = new SecureRandom();
			byte[] salt = new byte[AESService.SALT_SIZE];
			random.NextBytes(salt);

			// Create the AES Key using password and salt.
			aes.GenerateKey(password, salt);

			// Encode and Decode a string then compare to verify they are the same.
			string clear_text = "This is a test";
			byte[] enc_bytes = aes.Encode(UTF8Encoding.UTF8.GetBytes(clear_text));
			byte[] dec_bytes = aes.Decode(enc_bytes);
			string dec_text = UTF8Encoding.UTF8.GetString(dec_bytes);

			/**
			 * Compare the original and decrypted files.
			 */
			if (Compare.SafeEquals(UTF8Encoding.UTF8.GetBytes(clear_text), UTF8Encoding.UTF8.GetBytes(dec_text)))
			{
				Console.Out.WriteLine("Original and Decrypted are the same!");
			}
			else
			{
				Console.Out.WriteLine("Original and Decrypted are NOT the same!");
			}
			Console.Out.WriteLine("End Example_060.");
		}
		public void TestGetAesKey()
		{
			Console.Out.WriteLine("getAesKey");
			AESService instance = new AESService();
			instance.GenerateKey();

			byte[] result = instance.GetAesKey();

			Assert.IsNotNull(result);
		}
		public void TestGenerateSalt()
		{
			Console.Out.WriteLine("generateSalt");
			AESService instance = new AESService();
			byte[] saltBytes = instance.GenerateSalt();

			WriteSaltBytes(saltBytes);

			Assert.IsNotNull(saltBytes);
		}
		public static void Test()
		{
			Console.Out.WriteLine("Begin Example_030.");
			// Create some data to test with.
			Support.TestData(TESTDATA_FILE);

			/**
			 * Create a 256-bit AES key. AES keys are synchronous. One key can both
			 * encrypt and decrypt data.
			 */
			Console.Out.WriteLine("Begin Create AES Key.");
			AESService aes = new AESService();
			aes.GenerateKey();
			Console.Out.WriteLine("End Create AES Key.");

			/**
			 * Use AES key to encrypt a file stream directly to another file stream.
			 */
			Console.Out.WriteLine("Begin Encrypt Data.");
			using (FileStream outstream = new FileStream(TESTDATA_ENC_FILE, FileMode.Create),
				   instream = new FileStream(TESTDATA_FILE, FileMode.Open))
			{
					aes.Encode(instream, outstream);
			}
			Console.Out.WriteLine("End Encrypt Data.");

			/**
			 * Now decrypt the encrypted file using the same AES key.
			 */
			Console.Out.WriteLine("Begin Decrypt Data.");
			using (FileStream outstream = new FileStream(TESTDATA_DEC_FILE, FileMode.Create),
				   instream = new FileStream(TESTDATA_ENC_FILE, FileMode.Open))
			{
					aes.Decode(instream, outstream);
			}
			Console.Out.WriteLine("End Decrypt Data.");
					
			/**
			 * Compare the original and decrypted files.
			 */
			string shaOriginal = DigestSHA.Sha256(new FileStream(TESTDATA_FILE, FileMode.Open));
			string shaDecripted = DigestSHA.Sha256(new FileStream(TESTDATA_DEC_FILE, FileMode.Open));
			if (Compare.SafeEquals(UTF8Encoding.UTF8.GetBytes(shaOriginal), UTF8Encoding.UTF8.GetBytes(shaDecripted)))
			{
				Console.Out.WriteLine("Encrypted and decrypted files are the same.");
			}
			else
			{
				Console.Out.WriteLine("Encrypted and decrypted files are NOT the same.");
			}
			Console.Out.WriteLine("End Example_030.");
		}
		public void TestGetHmac256Digest()
		{
			Console.Out.WriteLine("getHmac256Digest");

			// Need to use a hard coded salt so we get a predictable result from getHmac256Digest().
			string saltString = "253a3dd3a9aef71ca1fa2b8b3704d6724ba474342e3c2e4fd124ee74d2c56017f4a7c22951a99978c6fdfbbefb4cf775d5642ea6dcb4d9b8e164fc23099f36c4";
			byte[] saltBytes = Hex.Decode(saltString);

			AESService instance = new AESService();
			instance.GenerateKey(password, saltBytes);

			String result = DigestSHA.Sha512(msgBytes);
			String expResult = "25296335d88536dddd09ffb7bcc09646dd9b3f537beb78cf89c76077d39daedd0cb8e46cf1e9b06a99e59e5b8b7f66f307978dc6413426b13d1f724a0a030529";

			Assert.IsTrue(expResult == result);
		}
		public void TestGenerateKey_String_byteArr()
		{
			Console.Out.WriteLine("generateKey");

			byte[] saltBytes = ReadSaltBytes();

			AESService instance = new AESService();
			instance.GenerateKey(password, saltBytes);

			byte[] aes_key = instance.GetAesKey();
			Assert.IsNotNull(aes_key);
		}
		public void TestEncodeAndDecode_InputStream_OutputStream()
		{
			Console.Out.WriteLine("encode and decode stream");

			byte[] saltBytes = ReadSaltBytes();

			AESService instance = new AESService();
			instance.GenerateKey(password, saltBytes);

			byte[] decData;
            byte[] encData;
			using (MemoryStream outstream = new MemoryStream())
			{
				using (MemoryStream instream = new MemoryStream(msgBytes))
				{
					instance.Encode(instream, outstream);
				}
				encData = outstream.ToArray();
				decData = instance.Decode(encData);

				Boolean bCompare = Compare.SafeEquals(msgBytes, decData);
				Assert.IsTrue(bCompare);
			}

            using (MemoryStream outstream = new MemoryStream())
            {
                using (MemoryStream instream = new MemoryStream(encData))
                {
                    instance.Decode(instream, outstream);
                }
                decData = outstream.ToArray();

                Boolean bCompare = Compare.SafeEquals(msgBytes, decData);
                Assert.IsTrue(bCompare);
            }
        }
        public void TestEncodeAndDecode_String()
        {
            Console.Out.WriteLine("encode and decode byte string");

            byte[] saltBytes = ReadSaltBytes();

            AESService instance = new AESService();
            instance.GenerateKey(password, saltBytes);

            byte[] encData = instance.Encode(msgString);
            string encString = Hex.Encode(encData);
            byte[] decData = instance.Decode(encString);

            Boolean bCompare = Compare.SafeEquals(msgBytes, decData);
            Assert.IsTrue(bCompare);
        }