2 // RSAKeyValueTest.cs - NUnit Test Cases for RSAKeyValue
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
11 using System
.Security
.Cryptography
;
12 using System
.Security
.Cryptography
.Xml
;
15 using NUnit
.Framework
;
17 namespace MonoTests
.System
.Security
.Cryptography
.Xml
{
20 public class RSAKeyValueTest
: Assertion
{
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
));
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
));
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 ();
47 RSAKeyValue rsa1
= new RSAKeyValue ();
48 rsa1
.LoadXml (doc
.DocumentElement
);
50 string s
= (rsa1
.GetXml ().OuterXml
);
51 AssertEquals ("RSA Key", rsaKey
, s
);
55 [ExpectedException (typeof (ArgumentNullException
))]
56 public void InvalidValue1 ()
58 RSAKeyValue rsa
= new RSAKeyValue ();
63 [ExpectedException (typeof (CryptographicException
))]
64 public void InvalidValue2 ()
66 string badKey
= "<Test></Test>";
67 XmlDocument doc
= new XmlDocument ();
70 RSAKeyValue rsa
= new RSAKeyValue ();
71 rsa
.LoadXml (doc
.DocumentElement
);