public async Task ReadAsync_EmptyStream_EmptyStreamEncrypted()
        {
            var cryptoStream = new SymmetricEncryptStream(
                new MemoryStream(),
                new SymmetricEncryptionSettings
            {
                Key = GenerateKey(256)
            });

            var result = await cryptoStream.ReadAllAsync();

            result.Should().HaveCount(32);
        }
        public async Task ReadAsync_WithoutSpecifyingIV_IVIsGeneratedAndPrepended()
        {
            var cryptoStream = new SymmetricEncryptStream(
                new MemoryStream(ClearTextMessage),
                new SymmetricEncryptionSettings
            {
                Key = GenerateKey(256)
            });

            var result = await cryptoStream.ReadAllAsync();

            result.Should().NotBeNull();
            result !.Length.Should().Be(AesDefaultBlockSizeInBytes + AesDefaultInitializationVectorSizeInBytes);
        }
        public async Task ReadAsync_UsingDefaultAesAlgorithmWithDefaultSettings_MessageIsSuccessfullyEncrypted()
        {
            var cryptoStream = new SymmetricEncryptStream(
                new MemoryStream(ClearTextMessage),
                new SymmetricEncryptionSettings
            {
                Key = GenerateKey(256)
            });

            var result = await cryptoStream.ReadAllAsync();

            result.Should().NotBeNull();
            result !.Length.Should().Be(AesDefaultBlockSizeInBytes + AesDefaultInitializationVectorSizeInBytes);
            result.Should().NotBeEquivalentTo(ClearTextMessage);
        }
        public async Task ReadAsync_SpecifyingIV_IVIsNotPrepended()
        {
            var iv = GenerateKey(128);

            var cryptoStream = new SymmetricEncryptStream(
                new MemoryStream(ClearTextMessage),
                new SymmetricEncryptionSettings
            {
                Key = GenerateKey(256),
                InitializationVector = iv
            });

            var result = await cryptoStream.ReadAllAsync();

            result.Should().NotBeNull();
            result !.Length.Should().Be(AesDefaultBlockSizeInBytes);

            result.Take(iv.Length).Should().NotBeEquivalentTo(iv);
        }
        public async Task ReadAsync_UsingRijndaelWithCustomSettings_MessageIsSuccessfullyEncrypted()
        {
            var cryptoStream = new SymmetricEncryptStream(
                new MemoryStream(ClearTextMessage),
                new SymmetricEncryptionSettings
            {
                AlgorithmName = "Rijndael",
                BlockSize     = 128,
                FeedbackSize  = 64,
                Key           = GenerateKey(128),
                CipherMode    = CipherMode.ECB,
                PaddingMode   = PaddingMode.ISO10126
            });

            var result = await cryptoStream.ReadAllAsync();

            result.Should().NotBeNull();
            result !.Length.Should().Be((128 * 2) / 8);
            result.Should().NotBeEquivalentTo(ClearTextMessage);
        }
        public async Task ReadAsync_TwiceWithoutSpecifyingIV_ResultIsDifferent()
        {
            var cryptoStream1 = new SymmetricEncryptStream(
                new MemoryStream(ClearTextMessage),
                new SymmetricEncryptionSettings
            {
                Key = GenerateKey(256)
            });
            var cryptoStream2 = new SymmetricEncryptStream(
                new MemoryStream(ClearTextMessage),
                new SymmetricEncryptionSettings
            {
                Key = GenerateKey(256)
            });

            var result1 = await cryptoStream1.ReadAllAsync();

            var result2 = await cryptoStream2.ReadAllAsync();

            result2.Should().NotBeEquivalentTo(result1);
        }
        public async Task ReadAsync_TwiceWithSameIV_ResultIsEqual()
        {
            var cryptoStream1 = new SymmetricEncryptStream(
                new MemoryStream(ClearTextMessage),
                new SymmetricEncryptionSettings
            {
                Key = GenerateKey(256),
                InitializationVector = GenerateKey(128)
            });
            var cryptoStream2 = new SymmetricEncryptStream(
                new MemoryStream(ClearTextMessage),
                new SymmetricEncryptionSettings
            {
                Key = GenerateKey(256),
                InitializationVector = GenerateKey(128)
            });

            var result1 = await cryptoStream1.ReadAllAsync();

            var result2 = await cryptoStream2.ReadAllAsync();

            result2.Should().BeEquivalentTo(result1);
        }
        public async Task ReadAsync_TwiceWithoutSpecifyingIV_GeneratedIVIsDifferent()
        {
            var cryptoStream1 = new SymmetricEncryptStream(
                new MemoryStream(ClearTextMessage),
                new SymmetricEncryptionSettings
            {
                Key = GenerateKey(256)
            });
            var cryptoStream2 = new SymmetricEncryptStream(
                new MemoryStream(ClearTextMessage),
                new SymmetricEncryptionSettings
            {
                Key = GenerateKey(256)
            });

            var result1 = await cryptoStream1.ReadAllAsync();

            var result2 = await cryptoStream2.ReadAllAsync();

            var iv1 = result1 !.Take(AesDefaultInitializationVectorSizeInBytes);
            var iv2 = result2 !.Take(AesDefaultInitializationVectorSizeInBytes);

            iv2.Should().NotBeEquivalentTo(iv1);
        }