Ejemplo n.º 1
0
        public void SelfTestCbc()
        {
            var r     = new Random(42);
            var plain = new byte[DataSize];
            var key   = new byte[16];
            var iv    = new byte[16];

            r.NextBytes(plain);
            r.NextBytes(key);
            r.NextBytes(iv);

            var cipher     = new byte[DataSize];
            var plainAgain = new byte[DataSize];
            var k          = new Aes128Key(key);

            Aes.EncryptCbc(plain, cipher, iv, k, PaddingMode.None);
            Aes.DecryptCbc(cipher, plainAgain, iv, k, PaddingMode.None);

            Assert.Equal(plain, plainAgain);
        }
Ejemplo n.º 2
0
        public void ReferenceTestCbc()
        {
            var r     = new Random(42);
            var bytes = new byte[DataSize];
            var key   = new byte[16];
            var iv    = new byte[16];

            r.NextBytes(bytes);
            r.NextBytes(key);
            r.NextBytes(iv);

            var managed = new AesManaged {
                Key = key, IV = iv, Mode = CipherMode.CBC, Padding = PaddingMode.None
            };
            var managedResult = managed.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);

            var niResult = new byte[DataSize];

            Aes.EncryptCbc(bytes, niResult, iv, new Aes128Key(key), PaddingMode.None);

            Assert.Equal(managedResult, niResult);
        }