DSAKeyValue.cs 1.3 KB

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