Пример #1
0
        private static void ShowWikipediaTestVectors()
        {
            WriteHeader("Wikipedia Test Vectors Comparison");
            // Test vectors came from http://en.wikipedia.org/wiki/Advanced_Encryption_Standard#Test_vectors on 7 Sep 2009
            byte[] input               = ByteUtilities.GetBytes("4EC137A426DABF8AA0BEB8BC0C2B89D6");
            byte[] aes128Key           = ByteUtilities.GetBytes("95A8EE8E89979B9EFDCBC6EB9797528D");
            byte[] cipheredOutput128   = Aes.Encrypt(input, aes128Key);
            byte[] decipheredOutput128 = Aes.Decrypt(input, aes128Key);

            byte[] wikipediaExpectedCipheredOutput128   = ByteUtilities.GetBytes("D9B65D1232BA0199CDBD487B2A1FD646");
            byte[] wikipediaExpectedDecipheredOutput128 = ByteUtilities.GetBytes("9570C34363565B393503A001C0E23B65");
            ByteUtilities.AssertBytesEqual(wikipediaExpectedCipheredOutput128, cipheredOutput128);
            ByteUtilities.AssertBytesEqual(wikipediaExpectedDecipheredOutput128, decipheredOutput128);

            byte[] aes192Key           = ByteUtilities.GetBytes("95A8EE8E89979B9EFDCBC6EB9797528D432DC26061553818");
            byte[] cipheredOutput192   = Aes.Encrypt(input, aes192Key);
            byte[] decipheredOutput192 = Aes.Decrypt(input, aes192Key);

            byte[] wikipediaExpectedCipheredOutput192   = ByteUtilities.GetBytes("B18BB3E7E10732BE1358443A504DBB49");
            byte[] wikipediaExpectedDecipheredOutput192 = ByteUtilities.GetBytes("29DFD75B85CEE4DE6E26A808CDC2C9C3");

            ByteUtilities.AssertBytesEqual(wikipediaExpectedCipheredOutput192, cipheredOutput192);
            ByteUtilities.AssertBytesEqual(wikipediaExpectedDecipheredOutput192, decipheredOutput192);

            byte[] aes256Key           = ByteUtilities.GetBytes("95A8EE8E89979B9EFDCBC6EB9797528D432DC26061553818EA635EC5D5A7727E");
            byte[] cipheredOutput256   = Aes.Encrypt(input, aes256Key);
            byte[] decipheredOutput256 = Aes.Decrypt(input, aes256Key);

            byte[] wikipediaExpectedCipheredOutput256   = ByteUtilities.GetBytes("2F9CFDDBFFCDE6B9F37EF8E40D512CF4");
            byte[] wikipediaExpectedDecipheredOutput256 = ByteUtilities.GetBytes("110A3545CE49B84BBB7B35236108FA6E");

            ByteUtilities.AssertBytesEqual(wikipediaExpectedCipheredOutput256, cipheredOutput256);
            ByteUtilities.AssertBytesEqual(wikipediaExpectedDecipheredOutput256, decipheredOutput256);
            Console.WriteLine("6 vectors passed");
        }
        private static void ParseNamedBytes(string line, out string name, out byte[] bytes, out int bitLength)
        {
            string[] nameValue = ParseNameValuePair(line);
            name = nameValue[0];

            if (nameValue[1].Length == 1)
            {
                bitLength = 1;
                bytes     = new[] { (byte)(Int32.Parse(nameValue[1]) * 0x80) };
                return;
            }

            bytes     = ByteUtilities.GetBytes(nameValue[1]);
            bitLength = bytes.Length * Constants.BitsPerByte;
        }