Ejemplo n.º 1
0
        public void DecryptShouldTakeIntoAccountPaddingForLengthOfOutputBufferPassedToDecryptBlock()
        {
            var input       = new byte[] { 0x2c, 0x1a, 0x05, 0x00, 0x68 };
            var output      = new byte[] { 0x0a, 0x00, 0x03, 0x02, 0x06, 0x08, 0x07, 0x05 };
            var key         = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 };
            var blockCipher = new BlockCipherStub(key, 8, null, new PKCS5Padding())
            {
                DecryptBlockDelegate = (inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset) =>
                {
                    Assert.AreEqual(8, outputBuffer.Length);
                    Buffer.BlockCopy(output, 0, outputBuffer, 0, output.Length);
                    return(inputBuffer.Length);
                }
            };

            var actual = blockCipher.Decrypt(input);

            Assert.IsTrue(output.SequenceEqual(actual));
        }
Ejemplo n.º 2
0
        public void DecryptShouldTakeIntoAccountPaddingForLengthOfOutputBufferPassedToDecryptBlock()
        {
            var input = new byte[] { 0x2c, 0x1a, 0x05, 0x00, 0x68 };
            var output = new byte[] { 0x0a, 0x00, 0x03, 0x02, 0x06, 0x08, 0x07, 0x05 };
            var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 };
            var blockCipher = new BlockCipherStub(key, 8, null, new PKCS5Padding())
                {
                    DecryptBlockDelegate = (inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset) =>
                        {
                            Assert.AreEqual(8, outputBuffer.Length);
                            Buffer.BlockCopy(output, 0, outputBuffer, 0, output.Length);
                            return inputBuffer.Length;
                        }
                };

            var actual = blockCipher.Decrypt(input);

            Assert.IsTrue(output.SequenceEqual(actual));
        }