Example #1
0
        public void EnsureCompatAes()
        {
            RijndaelManaged r = new RijndaelManaged();

            foreach (int blksz in AllKeySizes(r.LegalBlockSizes))
            {
                r.BlockSize = blksz;
                r.GenerateIV();

                foreach (int keysz in AllKeySizes(r.LegalKeySizes))
                {
                    r.KeySize = keysz;
                    r.GenerateKey();

                    ModifiedRijndael modified = ModifiedRijndael.Create(typeof(ModifiedRijndael).FullName);
                    modified.BlockSize = r.BlockSize;
                    modified.KeySize   = r.KeySize;
                    modified.IV        = r.IV;
                    modified.Key       = r.Key;
                    modified.Padding   = r.Padding;
                    modified.Mode      = r.Mode;

                    TestEncryptDecrypt(r, modified);
                    TestEncryptDecrypt(modified, r);
                }
            }
        }
Example #2
0
        private void TestAes256CBC(bool enc, string key, string iv, string input, string expect)
        {
            ModifiedRijndael r = ModifiedRijndael.Create();

            r.Mode      = CipherMode.CBC;
            r.Padding   = PaddingMode.None;
            r.BlockSize = iv.Length / 2 * 8;
            r.IV        = HexEncoding.DecodeBytes(iv);
            r.KeySize   = key.Length / 2 * 8;
            r.Key       = HexEncoding.DecodeBytes(key);
            ICryptoTransform xf = enc ? r.CreateEncryptor() : r.CreateDecryptor();

            byte[] result = xf.TransformFinalBlock(HexEncoding.DecodeBytes(input), 0, input.Length / 2);
            byte[] test   = HexEncoding.DecodeBytes(expect);
            Assert.AreEqual(0, BinaryComparer.Compare(test, result));
        }
Example #3
0
        public void TestCycleAll()
        {
            ModifiedRijndael r = new ModifiedRijndael();

            foreach (int blksz in AllKeySizes(r.LegalBlockSizes))
            {
                r.BlockSize = blksz;
                r.GenerateIV();
                Assert.AreEqual(blksz, r.IV.Length * 8);

                foreach (int keysz in AllKeySizes(r.LegalKeySizes))
                {
                    r.KeySize = keysz;
                    r.GenerateKey();
                    Assert.AreEqual(keysz, r.Key.Length * 8);

                    r.Rounds = r.NormalRounds;
                    TestEncryptDecrypt(r, r);
                    r.Rounds = r.MaxRounds;
                    TestEncryptDecrypt(r, r);
                }
            }
        }