RSAKeyValue.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. static private string xmldsig = "http://www.w3.org/2000/09/xmldsig#";
  14. private RSA rsa;
  15. public RSAKeyValue ()
  16. {
  17. rsa = RSA.Create ();
  18. }
  19. public RSAKeyValue (RSA key)
  20. {
  21. rsa = key;
  22. }
  23. public RSA Key {
  24. get { return rsa; }
  25. set { rsa = value; }
  26. }
  27. public override XmlElement GetXml ()
  28. {
  29. StringBuilder sb = new StringBuilder ();
  30. sb.Append ("<KeyValue xmlns=\"");
  31. sb.Append (xmldsig);
  32. sb.Append ("\">");
  33. sb.Append (rsa.ToXmlString (false));
  34. sb.Append ("</KeyValue>");
  35. XmlDocument doc = new XmlDocument ();
  36. doc.LoadXml(sb.ToString ());
  37. return doc.DocumentElement;
  38. }
  39. public override void LoadXml (XmlElement value)
  40. {
  41. if (value == null)
  42. throw new ArgumentNullException ();
  43. if ((value.LocalName == "KeyValue") && (value.NamespaceURI == xmldsig))
  44. rsa.FromXmlString (value.InnerXml);
  45. else
  46. throw new CryptographicException ("value");
  47. }
  48. }
  49. }