public void Decrypt_File_WhiteSpacePassword()
 {
     try
     {
         EncryptorImplementation Encryptor = new EncryptorImplementation(Mock.Of<IAESAlgorithm>(), Mock.Of<IHashAlgorithm>(), Mock.Of<IFile>());
         Encryptor.Decrypt("TestInput", "TestOutput", "\t");
         Assert.Fail("An ArgumentException was expected.");
     }
     catch(System.ArgumentException) { }
 }
        public void DecryptTest()
        {
            byte[] bytesToDecrypt = new byte[] { 1, 2, 3, 4, 5, 6 };
            byte[] expectedDecryptedBytes = new byte[] { 2, 4, 6, 8, 10, 12 };
            byte[] hashedPasswordBytes = new byte[] {
                                                        1, 2, 3, 4, 5, 6, 7, 8,
                                                        1, 2, 3, 4, 5, 6, 7, 7,
                                                        1, 2, 3, 4, 5, 6, 7, 6,
                                                        1, 2, 3, 4, 5, 6, 7, 5,
                                                        1, 2, 3, 4, 5, 6, 7, 4,
                                                        1, 2, 3, 4, 5, 6, 7, 3,
                                                        1, 2, 3, 4, 5, 6, 7, 2,
                                                        1, 2, 3, 4, 5, 6, 7, 1,
                                                    };
            string password = "******";
            System.Func<byte, byte> transformMethod = (a) =>
            {
                if(a >= 127)
                    return System.Byte.MaxValue;
                return (byte)(a * 2);
            };

            MemoryStream streamToDecrypt = new MemoryStream(bytesToDecrypt);
            MemoryStream outputStream = new MemoryStream();

            Mock<IHashAlgorithm> hashMock = new Mock<IHashAlgorithm>();
            Mock<IAESAlgorithm> aesMock = new Mock<IAESAlgorithm>();
            DummyEncryptor transform = new DummyEncryptor(transformMethod, 16);

            hashMock.Setup(a => a.ComputeHash(It.IsAny<byte[]>())).Returns(hashedPasswordBytes);
            aesMock.Setup(a => a.CreateDecryptor(It.IsAny<byte[]>(), It.IsAny<byte[]>())).Returns(transform);

            EncryptorImplementation Encryptor = new EncryptorImplementation(aesMock.Object, hashMock.Object, Mock.Of<IFile>());

            Encryptor.Decrypt(streamToDecrypt, outputStream, password);

            outputStream.Position = 0;
            CollectionAssert.AreEqual(expectedDecryptedBytes, outputStream.ToArray());
        }
 public void DecryptTest_NullPassword()
 {
     try
     {
         var target = new EncryptorImplementation(Mock.Of<IAESAlgorithm>(), Mock.Of<IHashAlgorithm>(), Mock.Of<IFile>());
         target.Decrypt(Mock.Of<System.IO.Stream>(), Mock.Of<System.IO.Stream>(), null);
         Assert.Fail("An ArgumentException was expected.");
     }
     catch(System.ArgumentException) { }
 }