Rijndael vs TripleDES in .Net (performance)
Today, I was in front of a dilemma which algorithm to use? Rijndael or TripleDES. As far as I know Rijndael is faster then TripleDES but i found some information about their realization in .Net which tells 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. Below is the code of my console application which I used for the test.
1: using System;
2: using System.IO;
3: using System.Security.Cryptography;
4: using System.Diagnostics;
5:
6: namespace AESvsTripleDES
7: {
8: class Program
9: {
10: static void Main(string[] args)
11: {
12: double rijndaelResult;
13: double tripleDesResult;
14:
15: using (SymmetricAlgorithm algorithm = Rijndael.Create())
16: {
17: rijndaelResult = RunTest(algorithm);
18: }
19:
20: using (SymmetricAlgorithm algorithm = TripleDES.Create())
21: {
22: tripleDesResult = RunTest(algorithm);
23: }
24:
25: Console.WriteLine("Rijndael Result = " + rijndaelResult.ToString());
26: Console.WriteLine("TripleDES Result = " + tripleDesResult.ToString());
27: Console.Read();
28: }
29:
30: private static double RunTest(SymmetricAlgorithm algorithm)
31: {
32: using (MemoryStream ms = new MemoryStream())
33: {
34: using (ICryptoTransform transform = algorithm.CreateEncryptor())
35: {
36: using (CryptoStream cs = new CryptoStream(ms, transform, CryptoStreamMode.Write))
37: {
38: byte[] data = new byte[8192];
39: Random r = new Random(255);
40: for (int i = 0; i < data.Length; i++)
41: {
42: data[i] = (byte)r.Next();
43: }
44: Stopwatch sw = new Stopwatch();
45:
46: sw.Start();
47: for (int i = 0; i < 10000000; i += data.Length)
48: {
49: cs.Write(data, 0, data.Length);
50: }
51: sw.Stop();
52: return sw.ElapsedMilliseconds;
53: }
54: }
55: }
56: }
57: }
58: }
The output of test execution is shown below.

Leave a Reply