Пример #1
0
        public void ZeroPaddingVector(byte[] input, int blockSize, byte[] reference)
        {
            var blkCipher = new NoOpSingleBlockTransform(blockSize);
            var enc       = new ZerosPaddingTransform(blkCipher, false);
            var padded    = enc.TransformFinalBlock(input, 0, input.Length);

            Assert.Equal(reference.AsEnumerable(), padded);

            Assert.True(enc.CanReuseTransform);
            Assert.False(enc.CanTransformMultipleBlocks);
        }
Пример #2
0
        public void Pkcs7PaddingVector(byte[] input, int blockSize, byte[] reference)
        {
            var blkCipher = new NoOpSingleBlockTransform(blockSize);
            var enc       = new PaddingTransform(blkCipher, PaddingMode.PKCS7, false);
            var dec       = new PaddingTransform(blkCipher, PaddingMode.PKCS7, true);
            var padded    = enc.TransformFinalBlock(input, 0, input.Length);

            Assert.Equal(reference.AsEnumerable(), padded);

            using (var unPadded = new MemoryStream()) {
                using (var cryptoStream = new CryptoStream(unPadded, dec, CryptoStreamMode.Write)) {
                    for (var i = 0; i < padded.Length; i += blockSize)
                    {
                        cryptoStream.Write(padded, i, blockSize);
                    }
                }

                Assert.Equal(input.AsEnumerable(), unPadded.ToArray());
            }

            Assert.True(enc.CanReuseTransform);
            Assert.False(enc.CanTransformMultipleBlocks);
        }