public void CompareBytes_IdenticalInput_ReturnsTrue()
            {
                AesCryptography aes = new AesCryptography();

                // Test that identical inputs will result in 'true' being returned.
                Assert.IsTrue(aes.CompareBytes(Encoding.UTF8.GetBytes(BYTE_STREAM1), Encoding.UTF8.GetBytes(BYTE_STREAM_IDENTICAL_TO_STREAM1)));
            }
            public void CompareBytes_DifferentLengthOfArguments_ReturnsFalse()
            {
                AesCryptography aes = new AesCryptography();

                // Test that different length of inputs will result in 'false' being returned.
                Assert.IsFalse(aes.CompareBytes(Encoding.UTF8.GetBytes(BYTE_STREAM1), Encoding.UTF8.GetBytes(LONGER_BYTE_STREAM)));
            }
            public void CompareBytes_DifferentInputInArguments_ReturnsFalse()
            {
                AesCryptography aes = new AesCryptography();

                // Test that different inputs will result in 'false' being returned eventhough the input length are identical.
                Assert.IsFalse(aes.CompareBytes(Encoding.UTF8.GetBytes(BYTE_STREAM1), Encoding.UTF8.GetBytes(BYTE_STREAM2)));

                // Test that identical inputs will result in 'true' being returned.
                Assert.IsTrue(aes.CompareBytes(Encoding.UTF8.GetBytes(BYTE_STREAM1), Encoding.UTF8.GetBytes(BYTE_STREAM_IDENTICAL_TO_STREAM1)));
            }
 public void CreateAes_InvalidNullPasswordAndValidSalt_ThrowsArgumentException()
 {
     AesCryptography aes = new AesCryptography();
     aes.CreateAes(null, Encoding.UTF8.GetBytes(LONG_SALT));
 }
            public void EncryptDecrypt_ValidPasswordSalt_AreEqual()
            {
                AesCryptography aes = new AesCryptography();

                byte[] cipherText  = aes.Encrypt(SecurityIds.Password, Encoding.UTF8.GetBytes(SecurityIds.Salt), Encoding.UTF8.GetBytes(CLEAR_TEXT));
                byte[] inClearText = aes.Decrypt(SecurityIds.Password, Encoding.UTF8.GetBytes(SecurityIds.Salt), cipherText);

                Assert.AreEqual(CLEAR_TEXT, Encoding.UTF8.GetString(inClearText));

                try
                {
                    // Now let's do some tampering...
                    cipherText[30]++;

                    aes.Decrypt(SecurityIds.Password, Encoding.UTF8.GetBytes(SecurityIds.Salt), cipherText);
                    Assert.Fail("The 'Decrypt' method did not throw an exception eventhough data was tamered with!");
                }
                catch (Exception ex)
                {
                    Assert.IsTrue(ex is CryptographicException);
                }
            }
            public void EncryptDecrypt_TamperingEncryptedData_ThrowsCryptographicException()
            {
                AesCryptography aes = new AesCryptography();

                byte[] cipherText  = aes.Encrypt(SecurityIds.Password, Encoding.UTF8.GetBytes(SecurityIds.Salt), Encoding.UTF8.GetBytes(CLEAR_TEXT));
                byte[] inClearText = aes.Decrypt(SecurityIds.Password, Encoding.UTF8.GetBytes(SecurityIds.Salt), cipherText);

                // Now let's do some tampering...
                cipherText[30]++;

                aes.Decrypt(SecurityIds.Password, Encoding.UTF8.GetBytes(SecurityIds.Salt), cipherText);
            }
 public void CreateAes_ValidPasswordAndValidSalt_ReturnsAes()
 {
     AesCryptography aes = new AesCryptography();
     Assert.IsNotNull(aes.CreateAes(LONG_PASSWORD, Encoding.UTF8.GetBytes(LONG_SALT)));
 }
 public void CreateAes_ValidPasswordAndInvalidShortSalt_ThrowsArgumentException()
 {
     AesCryptography aes = new AesCryptography();
     aes.CreateAes(LONG_PASSWORD, Encoding.UTF8.GetBytes(TO_SHORT_SALT));
 }
 public void CreateAes_ValidPasswordAndInvalidNullSalt_ThrowsArgumentException()
 {
     AesCryptography aes = new AesCryptography();
     aes.CreateAes(LONG_PASSWORD, null);
 }