RSAKeyValue.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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)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. XmlElement xel = document.CreateElement (XmlSignature.ElementNames.KeyValue, XmlSignature.NamespaceURI);
  30. xel.SetAttribute ("xmlns", XmlSignature.NamespaceURI);
  31. xel.InnerXml = rsa.ToXmlString (false);
  32. return xel;
  33. }
  34. public override void LoadXml (XmlElement value)
  35. {
  36. if (value == null)
  37. throw new ArgumentNullException ();
  38. if ((value.LocalName != XmlSignature.ElementNames.KeyValue) || (value.NamespaceURI != XmlSignature.NamespaceURI))
  39. throw new CryptographicException ("value");
  40. rsa.FromXmlString (value.InnerXml);
  41. }
  42. }
  43. }