This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / class / corlib / Test / System.Security.Cryptography / TripleDESTest.cs
1 //
2 // TripleDESTest.cs - NUnit Test Cases for TripleDES
3 //
4 // Author:
5 //      Sebastien Pouliot (sebastien@ximian.com)
6 //
7 // (C) 2004 Novell (http://www.novell.com)
8 //
9
10 using NUnit.Framework;
11 using System;
12 using System.Security.Cryptography;
13
14 namespace MonoTests.System.Security.Cryptography {
15
16         [TestFixture]
17         public class TripleDESTest : Assertion {
18
19                 [Test]
20                 public void Key ()
21                 {
22                         TripleDES algo = TripleDES.Create ();
23                         algo.GenerateKey ();
24                         algo.GenerateIV ();
25                         AssertEquals ("Key Size", 192, algo.KeySize);
26                         AssertEquals ("Key Length", 24, algo.Key.Length);
27                         AssertEquals ("IV Length", 8, algo.IV.Length);
28                 }
29
30                 [Test]
31                 [ExpectedException (typeof (ArgumentNullException))]
32                 public void KeyNull () 
33                 {
34                         TripleDES algo = TripleDES.Create ();
35                         algo.Key = null;
36                 }
37
38                 [Test]
39                 [ExpectedException (typeof (CryptographicException))]
40                 public void KeyWeak128bits () 
41                 {
42                         byte[] wk128 = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
43                         TripleDES algo = TripleDES.Create ();
44                         algo.Key = wk128;
45                 }
46
47                 [Test]
48                 [ExpectedException (typeof (CryptographicException))]
49                 public void KeyWeak192bits_AB () 
50                 {
51                         byte[] wk192 = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD };
52                         TripleDES algo = TripleDES.Create ();
53                         algo.Key = wk192;
54                 }
55
56                 [Test]
57                 [ExpectedException (typeof (CryptographicException))]
58                 public void KeyWeak192bits_BC () 
59                 {
60                         byte[] wk192 = { 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
61                         TripleDES algo = TripleDES.Create ();
62                         algo.Key = wk192;
63                 }
64
65                 [Test]
66                 [ExpectedException (typeof (CryptographicException))]
67                 public void KeyWrongLength () 
68                 {
69                         byte[] wk64 = { 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD };
70                         TripleDES algo = TripleDES.Create ();
71                         algo.Key = wk64;
72                 }
73         }
74 }