DSAKeyValue.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // DSAKeyValue.cs - DSA KeyValue 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.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. XmlDocument document = new XmlDocument ();
  31. document.LoadXml ("<KeyValue xmlns=\"" + XmlSignature.NamespaceURI + "\">" + dsa.ToXmlString (false) + "</KeyValue>");
  32. return document.DocumentElement;
  33. // FIX: this way we get a xmlns="" in DSAKeyValue
  34. /* XmlElement xel = document.CreateElement (XmlSignature.ElementNames.KeyValue, XmlSignature.NamespaceURI);
  35. xel.InnerXml = dsa.ToXmlString (false);
  36. return xel;*/
  37. }
  38. public override void LoadXml (XmlElement value)
  39. {
  40. if (value == null)
  41. throw new ArgumentNullException ();
  42. // FIXME: again hack to match MS implementation (required for previous hack)
  43. if ((value.LocalName != XmlSignature.ElementNames.KeyValue) || ((value.NamespaceURI != XmlSignature.NamespaceURI) && (value.GetAttribute("xmlns") != XmlSignature.NamespaceURI)))
  44. throw new CryptographicException ("value");
  45. dsa.FromXmlString (value.InnerXml);
  46. }
  47. }
  48. }