RSAKeyValue.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // RSAKeyValue.cs - RSAKeyValue implementation for XML Signature
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2002 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. StringBuilder sb = new StringBuilder ();
  29. sb.Append ("<KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\">");
  30. sb.Append (rsa.ToXmlString (false));
  31. sb.Append ("</KeyValue>");
  32. XmlDocument doc = new XmlDocument ();
  33. doc.LoadXml(sb.ToString ());
  34. return doc.DocumentElement;
  35. }
  36. public override void LoadXml (XmlElement value)
  37. {
  38. if (value == null)
  39. throw new ArgumentNullException ();
  40. if ((value.LocalName == "KeyValue") && (value.NamespaceURI == "http://www.w3.org/2000/09/xmldsig#"))
  41. rsa.FromXmlString (value.InnerXml);
  42. else
  43. throw new CryptographicException ("value");
  44. }
  45. }
  46. }