Exemplo n.º 1
0
        private static void ShowRijndaelBookTestVectors()
        {
            WriteHeader("Rijndael Book Test");
            Console.WriteLine("Here are the test vectors from Appendix D of \"The Design of Rijndael\" book.");
            Console.WriteLine("(Note how there are more variants than AES allows)");
            Console.WriteLine();
            for (int keyLength = 128; keyLength <= 256; keyLength += 32)
            {
                for (int blockLength = 128; blockLength <= 256; blockLength += 32)
                {
                    Console.WriteLine("block length {0}  key length {1}", blockLength, keyLength);
                    byte[] blockBytes = new byte[blockLength / Constants.BitsPerByte];
                    byte[] keyBytes   = new byte[keyLength / Constants.BitsPerByte];

                    var encrypted = Rijndael.Encrypt(blockBytes, keyBytes);
                    ByteUtilities.WriteBytes(encrypted);
                    var decrypted = Rijndael.Decrypt(encrypted, keyBytes);

                    for (int i = 0; i < decrypted.Length; i++)
                    {
                        if (decrypted[i] != 0)
                        {
                            throw new CryptographicException("The decrypted Rijndael book values were not all zero.");
                        }
                    }

                    var encryptedAgain = Rijndael.Encrypt(encrypted, keyBytes);
                    ByteUtilities.WriteBytes(encryptedAgain);

                    var decryptedAgain = Rijndael.Decrypt(encryptedAgain, keyBytes);
                    ByteUtilities.AssertBytesEqual(decryptedAgain, encrypted);
                    Console.WriteLine();
                }
            }
            Console.WriteLine();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Encrypts a block of data.
 /// </summary>
 /// <param name="input">The plaintext block.</param>
 /// <returns>The resulting ciphertext.</returns>
 public byte[] Encrypt(byte[] input)
 {
     return(_Rijndael.Encrypt(input));
 }