RSAKeyValue.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // RSAKeyValue.cs - RSAKeyValue implementation for XML Signature
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  8. //
  9. using System.Text;
  10. using System.Xml;
  11. namespace System.Security.Cryptography.Xml {
  12. public class RSAKeyValue : KeyInfoClause {
  13. private RSA rsa;
  14. public RSAKeyValue ()
  15. {
  16. rsa = RSA.Create ();
  17. }
  18. public RSAKeyValue (RSA key)
  19. {
  20. rsa = key;
  21. }
  22. public RSA Key {
  23. get { return rsa; }
  24. set { rsa = value; }
  25. }
  26. public override XmlElement GetXml ()
  27. {
  28. XmlDocument document = new XmlDocument ();
  29. document.LoadXml ("<KeyValue xmlns=\"" + XmlSignature.NamespaceURI + "\">" + rsa.ToXmlString (false) + "</KeyValue>");
  30. return document.DocumentElement;
  31. // FIX: this way we get a xmlns="" in RSAKeyValue
  32. /* XmlElement xel = document.CreateElement (XmlSignature.ElementNames.KeyValue, XmlSignature.NamespaceURI);
  33. xel.InnerXml = rsa.ToXmlString (false);
  34. return xel;*/
  35. }
  36. public override void LoadXml (XmlElement value)
  37. {
  38. if (value == null)
  39. throw new ArgumentNullException ();
  40. // FIXME: again hack to match MS implementation (required for previous hack)
  41. if ((value.LocalName != XmlSignature.ElementNames.KeyValue) || ((value.NamespaceURI != XmlSignature.NamespaceURI) && (value.GetAttribute("xmlns") != XmlSignature.NamespaceURI)))
  42. throw new CryptographicException ("value");
  43. rsa.FromXmlString (value.InnerXml);
  44. }
  45. }
  46. }