**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Xml / RSAKeyValueTest.cs
blob340da0d6092d9b6805da88f32135411e929a6626
1 //
2 // RSAKeyValueTest.cs - NUnit Test Cases for RSAKeyValue
3 //
4 // Author:
5 // Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
10 using System;
11 using System.Security.Cryptography;
12 using System.Security.Cryptography.Xml;
13 using System.Xml;
15 using NUnit.Framework;
17 namespace MonoTests.System.Security.Cryptography.Xml {
19 [TestFixture]
20 public class RSAKeyValueTest : Assertion {
22 [Test]
23 public void GeneratedKey ()
25 RSAKeyValue rsa1 = new RSAKeyValue ();
26 AssertNotNull ("Key", rsa1.Key);
27 XmlElement xmlkey = rsa1.GetXml ();
29 RSAKeyValue rsa2 = new RSAKeyValue ();
30 rsa2.LoadXml (xmlkey);
32 Assert ("rsa1==rsa2", (rsa1.GetXml ().OuterXml) == (rsa2.GetXml ().OuterXml));
34 RSA key = rsa1.Key;
35 RSAKeyValue rsa3 = new RSAKeyValue (key);
36 Assert ("rsa3==rsa1", (rsa3.GetXml ().OuterXml) == (rsa1.GetXml ().OuterXml));
37 Assert ("rsa3==rsa2", (rsa3.GetXml ().OuterXml) == (rsa2.GetXml ().OuterXml));
40 [Test]
41 public void ImportKey ()
43 string rsaKey = "<KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><RSAKeyValue><Modulus>ogZ1/O7iks9ncETqNxLDKoPvgrT4nFx1a3lOmpywEmgbc5+8vI5dSzReH4v0YrflY75rIJx13CYWMsaHfQ78GtXvaeshHlQ3lLTuSdYEJceKll/URlBoKQtOj5qYIVSFOIVGHv4Y/0lnLftOzIydem29KKH6lJQlJawBBssR12s=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue>";
44 XmlDocument doc = new XmlDocument ();
45 doc.LoadXml (rsaKey);
47 RSAKeyValue rsa1 = new RSAKeyValue ();
48 rsa1.LoadXml (doc.DocumentElement);
50 string s = (rsa1.GetXml ().OuterXml);
51 AssertEquals ("RSA Key", rsaKey, s);
54 [Test]
55 [ExpectedException (typeof (ArgumentNullException))]
56 public void InvalidValue1 ()
58 RSAKeyValue rsa = new RSAKeyValue ();
59 rsa.LoadXml (null);
62 [Test]
63 [ExpectedException (typeof (CryptographicException))]
64 public void InvalidValue2 ()
66 string badKey = "<Test></Test>";
67 XmlDocument doc = new XmlDocument ();
68 doc.LoadXml (badKey);
70 RSAKeyValue rsa = new RSAKeyValue ();
71 rsa.LoadXml (doc.DocumentElement);