コード例 #1
0
            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)));
            }
コード例 #2
0
            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)));
            }
コード例 #3
0
            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)));
            }
コード例 #4
0
 public void CreateAes_InvalidNullPasswordAndValidSalt_ThrowsArgumentException()
 {
     AesCryptography aes = new AesCryptography();
     aes.CreateAes(null, Encoding.UTF8.GetBytes(LONG_SALT));
 }
コード例 #5
0
            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);
                }
            }
コード例 #6
0
            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);
            }
コード例 #7
0
 public void CreateAes_ValidPasswordAndValidSalt_ReturnsAes()
 {
     AesCryptography aes = new AesCryptography();
     Assert.IsNotNull(aes.CreateAes(LONG_PASSWORD, Encoding.UTF8.GetBytes(LONG_SALT)));
 }
コード例 #8
0
 public void CreateAes_ValidPasswordAndInvalidShortSalt_ThrowsArgumentException()
 {
     AesCryptography aes = new AesCryptography();
     aes.CreateAes(LONG_PASSWORD, Encoding.UTF8.GetBytes(TO_SHORT_SALT));
 }
コード例 #9
0
 public void CreateAes_ValidPasswordAndInvalidNullSalt_ThrowsArgumentException()
 {
     AesCryptography aes = new AesCryptography();
     aes.CreateAes(LONG_PASSWORD, null);
 }