Rijndael vs TripleDES in .Net (performance)
By ganton ~ September 15th, 2008. Filed under: .Net.
Today, I was in front of a dilema which algorithm to use? Rijndael or TripleDES. As far as I know Rijndael is faster then TripleDES but i found some information about their realisation in .Net which tolds that in 2.0 TripleDES is even faster than Rijndael. As it is expected I decided to make a test in order to check is this true or not! The result I got is that they work almost with the same speed.
I have a machine with 2Gb RAM, CPU Core 2 Duo E8400 3GHz and .Net Framework 3.5 installed and used for the test. Belaw is the code of my console application which I used for the test.
using System;
using System.IO;
using System.Security.Cryptography;
using System.Diagnostics;
namespace AESvsTripleDES
{
class Program
{
static void Main(string[] args)
{
double rijndaelResult;
double tripleDesResult;
using (SymmetricAlgorithm algorithm = Rijndael.Create())
{
rijndaelResult = RunTest(algorithm);
}
using (SymmetricAlgorithm algorithm = TripleDES.Create())
{
tripleDesResult = RunTest(algorithm);
}
Console.WriteLine("Rijndael Result = " + rijndaelResult.ToString());
Console.WriteLine("TripleDES Result = " + tripleDesResult.ToString());
Console.Read();
}
private static double RunTest(SymmetricAlgorithm algorithm)
{
using (MemoryStream ms = new MemoryStream())
{
using (ICryptoTransform transform = algorithm.CreateEncryptor())
{
using (CryptoStream cs = new CryptoStream(ms, transform, CryptoStreamMode.Write))
{
byte[] data = new byte[8192];
Random r = new Random(255);
for (int i = 0; i < data.Length; i++)
{
data[i] = (byte)r.Next();
}
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 10000000; i += data.Length)
{
cs.Write(data, 0, data.Length);
}
sw.Stop();
return sw.ElapsedMilliseconds;
}
}
}
}
}
}
The output of test execution is shown below.
