RSAKeyValueTest.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // RSAKeyValueTest.cs - NUnit Test Cases for RSAKeyValue
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  8. //
  9. using System;
  10. using System.Security.Cryptography;
  11. using System.Security.Cryptography.Xml;
  12. using System.Xml;
  13. using NUnit.Framework;
  14. namespace MonoTests.System.Security.Cryptography.Xml {
  15. [TestFixture]
  16. public class RSAKeyValueTest {
  17. [Test]
  18. public void GeneratedKey ()
  19. {
  20. RSAKeyValue rsa1 = new RSAKeyValue ();
  21. Assert.IsNotNull (rsa1.Key, "Key");
  22. XmlElement xmlkey = rsa1.GetXml ();
  23. RSAKeyValue rsa2 = new RSAKeyValue ();
  24. rsa2.LoadXml (xmlkey);
  25. Assert.IsTrue ((rsa1.GetXml ().OuterXml) == (rsa2.GetXml ().OuterXml), "rsa1==rsa2");
  26. RSA key = rsa1.Key;
  27. RSAKeyValue rsa3 = new RSAKeyValue (key);
  28. Assert.IsTrue ((rsa3.GetXml ().OuterXml) == (rsa1.GetXml ().OuterXml), "rsa3==rsa1");
  29. Assert.IsTrue ((rsa3.GetXml ().OuterXml) == (rsa2.GetXml ().OuterXml), "rsa3==rsa2");
  30. }
  31. [Test]
  32. public void ImportKey ()
  33. {
  34. string rsaKey = "<KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><RSAKeyValue><Modulus>ogZ1/O7iks9ncETqNxLDKoPvgrT4nFx1a3lOmpywEmgbc5+8vI5dSzReH4v0YrflY75rIJx13CYWMsaHfQ78GtXvaeshHlQ3lLTuSdYEJceKll/URlBoKQtOj5qYIVSFOIVGHv4Y/0lnLftOzIydem29KKH6lJQlJawBBssR12s=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue>";
  35. XmlDocument doc = new XmlDocument ();
  36. doc.LoadXml (rsaKey);
  37. RSAKeyValue rsa1 = new RSAKeyValue ();
  38. rsa1.LoadXml (doc.DocumentElement);
  39. string s = (rsa1.GetXml ().OuterXml);
  40. Assert.AreEqual (rsaKey, s, "RSA Key");
  41. }
  42. [Test]
  43. [ExpectedException (typeof (ArgumentNullException))]
  44. public void InvalidValue1 ()
  45. {
  46. RSAKeyValue rsa = new RSAKeyValue ();
  47. rsa.LoadXml (null);
  48. }
  49. [Test]
  50. [ExpectedException (typeof (CryptographicException))]
  51. public void InvalidValue2 ()
  52. {
  53. string badKey = "<Test></Test>";
  54. XmlDocument doc = new XmlDocument ();
  55. doc.LoadXml (badKey);
  56. RSAKeyValue rsa = new RSAKeyValue ();
  57. rsa.LoadXml (doc.DocumentElement);
  58. }
  59. }
  60. }