Esempio n. 1
0
    static void AES(string name, int max, byte[] key, byte[] input, byte[] expected)
    {
        int i = 0;

        try {
            for (; i < max; i++)
            {
                using (Aes cipher = new AesKernel()) {
                    cipher.Mode    = CipherMode.ECB;
                    cipher.KeySize = key.Length * 8;
                    cipher.Padding = PaddingMode.Zeros;

                    byte[]           output    = new byte [input.Length];
                    ICryptoTransform encryptor = cipher.CreateEncryptor(key, aes_iv);
                    encryptor.TransformBlock(input, 0, input.Length, output, 0);
                    if (!Compare(output, expected))
                    {
                        throw new Exception("encryptor");
                    }

                    byte[]           original  = new byte [output.Length];
                    ICryptoTransform decryptor = cipher.CreateDecryptor(key, aes_iv);
                    decryptor.TransformBlock(output, 0, output.Length, original, 0);
                    if (!Compare(original, input))
                    {
                        throw new Exception("decryptor");
                    }
                }
                Process(name, i, max);
            }
        }
        catch (Exception e) {
            Console.WriteLine("{0} #{1} : {2}", name, i, e);
        }
    }
Esempio n. 2
0
    static void AES(string name, int max, byte[] key, byte[] input, byte[] expected)
    {
        int i = 0;
        try {
            for (; i < max; i++) {
                using (Aes cipher = new AesKernel ()) {
                    cipher.Mode = CipherMode.ECB;
                    cipher.KeySize = key.Length * 8;
                    cipher.Padding = PaddingMode.Zeros;

                    byte[] output = new byte [input.Length];
                    ICryptoTransform encryptor = cipher.CreateEncryptor (key, aes_iv);
                    encryptor.TransformBlock (input, 0, input.Length, output, 0);
                    if (!Compare (output, expected))
                        throw new Exception ("encryptor");

                    byte[] original = new byte [output.Length];
                    ICryptoTransform decryptor = cipher.CreateDecryptor (key, aes_iv);
                    decryptor.TransformBlock (output, 0, output.Length, original, 0);
                    if (!Compare (original, input))
                        throw new Exception ("decryptor");
                }
                Process (name, i, max);
            }
        }
        catch (Exception e) {
            Console.WriteLine ("{0} #{1} : {2}", name, i, e);
        }
    }