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 AesOpenSsl()) {
                    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
        public SymmetricAlgorithm GetAlgorithm(string name)
        {
            var result = new AesOpenSsl()
            {
                Mode         = CipherMode.CFB,
                FeedbackSize = 128,
                Padding      = PaddingMode.None,
                KeySize      = _ciphers[name],
            };

            return(result);
        }
Esempio n. 3
0
 public bool IsAvailable()
 {
     try
     {
         var algo = new AesOpenSsl()
         {
             Mode         = CipherMode.CFB,
             FeedbackSize = 128,
             Padding      = PaddingMode.None,
             KeySize      = 128
         };
         var enc    = algo.CreateEncryptor();
         var result = enc.TransformFinalBlock(
             new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 10);
         return(result.Length == 10);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 4
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 AesOpenSsl ()) {
                    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);
        }
    }