DSAKeyValue.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // DSAKeyValue.cs - DSAKeyInfo 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.Security.Cryptography;
  10. using System.Text;
  11. using System.Xml;
  12. namespace System.Security.Cryptography.Xml {
  13. public class DSAKeyValue : KeyInfoClause {
  14. private DSA dsa;
  15. public DSAKeyValue ()
  16. {
  17. dsa = DSA.Create ();
  18. }
  19. public DSAKeyValue (DSA key)
  20. {
  21. dsa = key;
  22. }
  23. public DSA Key
  24. {
  25. get { return dsa; }
  26. set { dsa = value; }
  27. }
  28. public override XmlElement GetXml ()
  29. {
  30. StringBuilder sb = new StringBuilder ();
  31. sb.Append ("<KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\">");
  32. sb.Append (dsa.ToXmlString (false));
  33. sb.Append ("</KeyValue>");
  34. XmlDocument doc = new XmlDocument ();
  35. doc.LoadXml(sb.ToString ());
  36. return doc.DocumentElement;
  37. }
  38. public override void LoadXml (XmlElement value)
  39. {
  40. if (value == null)
  41. throw new ArgumentNullException ();
  42. if ((value.LocalName == "KeyValue") && (value.NamespaceURI == "http://www.w3.org/2000/09/xmldsig#"))
  43. dsa.FromXmlString (value.InnerXml);
  44. else
  45. throw new CryptographicException ("value");
  46. }
  47. }
  48. }