Exemplo n.º 1
0
 public void TransformFinalBlockInvalidArgumentsTest()
 {
     using (var transform = new SimpleSymmetricAlgorithm())
     {
         using (var encryptor = transform.CreateDecryptor())
         {
             Assert.Throws <ArgumentNullException>(() => encryptor.TransformFinalBlock(null, 0, BlockSizeBytes));
             Assert.Throws <ArgumentOutOfRangeException>(() => encryptor.TransformFinalBlock(new byte[BlockSizeBytes], -1, BlockSizeBytes));
             Assert.Throws <ArgumentOutOfRangeException>(() => encryptor.TransformFinalBlock(new byte[BlockSizeBytes], 0, -1));
             Assert.Throws <ArgumentException>(() => encryptor.TransformFinalBlock(new byte[BlockSizeBytes], BlockSizeBytes, BlockSizeBytes));
         }
         using (var decryptor = transform.CreateDecryptor())
         {
             Assert.Throws <CryptographicException>(() => decryptor.TransformFinalBlock(new byte[BlockSizeBytes], 0, BlockSizeBytes - 1));
         }
     }
 }
Exemplo n.º 2
0
        public void TransformFinalBlock_Throws_IfParametersAreInvalid()
        {
            var inputBuffer = new byte[BlockSizeBytes];
            var inputCount  = BlockSizeBytes;
            var inputOffset = 0;

            using var transform = new SimpleSymmetricAlgorithm();
            using var encryptor = transform.CreateEncryptor();
            using var decryptor = transform.CreateDecryptor();

            Assert.Throws <ArgumentNullException>(nameof(inputBuffer),
                                                  () => encryptor.TransformFinalBlock(null !, inputOffset, inputCount));
            Assert.Throws <ArgumentOutOfRangeException>(nameof(inputOffset),
                                                        () => encryptor.TransformFinalBlock(inputBuffer, -1, inputCount));
            Assert.Throws <ArgumentOutOfRangeException>(nameof(inputCount),
                                                        () => encryptor.TransformFinalBlock(inputBuffer, inputOffset, -1));
            Assert.Throws <ArgumentException>(null,
                                              () => encryptor.TransformFinalBlock(inputBuffer, inputCount, inputCount));
            Assert.Throws <CryptographicException>(
                () => decryptor.TransformFinalBlock(inputBuffer, inputOffset, inputCount - 1));
        }