XmlSignature.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // XmlSignature.cs: Handles Xml Signature
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. // Atsushi Enomoto ([email protected])
  7. //
  8. // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
  9. // (C) 2004 Novell Inc.
  10. //
  11. using System;
  12. using System.Collections;
  13. using System.Xml;
  14. namespace System.Security.Cryptography.Xml {
  15. // following the design of WSE
  16. internal class XmlSignature {
  17. public class ElementNames {
  18. public const string CanonicalizationMethod = "CanonicalizationMethod";
  19. public const string DigestMethod = "DigestMethod";
  20. public const string DigestValue = "DigestValue";
  21. public const string DSAKeyValue = "DSAKeyValue";
  22. public const string HMACOutputLength = "HMACOutputLength";
  23. public const string KeyInfo = "KeyInfo";
  24. public const string KeyName = "KeyName";
  25. public const string KeyValue = "KeyValue";
  26. public const string Manifest = "Manifest";
  27. public const string Object = "Object";
  28. public const string Reference = "Reference";
  29. #if NET_1_0
  30. // RetrievalMethod vs RetrievalElement -> BUG in MS Framework 1.0
  31. public const string RetrievalMethod = "RetrievalElement";
  32. #else
  33. public const string RetrievalMethod = "RetrievalMethod";
  34. #endif
  35. public const string RSAKeyValue = "RSAKeyValue";
  36. public const string Signature = "Signature";
  37. public const string SignatureMethod = "SignatureMethod";
  38. public const string SignatureValue = "SignatureValue";
  39. public const string SignedInfo = "SignedInfo";
  40. public const string Transform = "Transform";
  41. public const string Transforms = "Transforms";
  42. public const string X509Data = "X509Data";
  43. public const string X509IssuerSerial = "X509IssuerSerial";
  44. public const string X509IssuerName = "X509IssuerName";
  45. public const string X509SerialNumber = "X509SerialNumber";
  46. public const string X509SKI = "X509SKI";
  47. public const string X509SubjectName = "X509SubjectName";
  48. public const string X509Certificate = "X509Certificate";
  49. public const string X509CRL = "X509CRL";
  50. public ElementNames () {}
  51. }
  52. public class AttributeNames {
  53. public const string Algorithm = "Algorithm";
  54. public const string Encoding = "Encoding";
  55. public const string Id = "Id";
  56. public const string MimeType = "MimeType";
  57. public const string Type = "Type";
  58. public const string URI = "URI";
  59. public AttributeNames () {}
  60. }
  61. public class AlgorithmNamespaces {
  62. public const string XmlDsigBase64Transform = "http://www.w3.org/2000/09/xmldsig#base64";
  63. public const string XmlDsigC14NTransform = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
  64. public const string XmlDsigC14NWithCommentsTransform = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments";
  65. public const string XmlDsigEnvelopedSignatureTransform = "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
  66. public const string XmlDsigXPathTransform = "http://www.w3.org/TR/1999/REC-xpath-19991116";
  67. public const string XmlDsigXsltTransform = "http://www.w3.org/TR/1999/REC-xslt-19991116";
  68. }
  69. public class Uri {
  70. public const string Manifest = "http://www.w3.org/2000/09/xmldsig#Manifest";
  71. }
  72. public const string NamespaceURI = "http://www.w3.org/2000/09/xmldsig#";
  73. public const string Prefix = "ds";
  74. public XmlSignature ()
  75. {
  76. }
  77. public static XmlElement GetChildElement (XmlElement xel, string element, string ns)
  78. {
  79. for (int i = 0; i < xel.ChildNodes.Count; i++) {
  80. XmlNode n = xel.ChildNodes [i];
  81. if (n.NodeType == XmlNodeType.Element && n.LocalName == element && n.NamespaceURI == ns)
  82. return n as XmlElement;
  83. }
  84. return null;
  85. }
  86. public static string GetAttributeFromElement (XmlElement xel, string attribute, string element)
  87. {
  88. XmlElement el = GetChildElement (xel, element, XmlSignature.NamespaceURI);
  89. return el != null ? el.GetAttribute (attribute) : null;
  90. }
  91. public static XmlElement [] GetChildElements (XmlElement xel, string element)
  92. {
  93. ArrayList al = new ArrayList ();
  94. for (int i = 0; i < xel.ChildNodes.Count; i++) {
  95. XmlNode n = xel.ChildNodes [i];
  96. if (n.NodeType == XmlNodeType.Element && n.LocalName == element && n.NamespaceURI == XmlSignature.NamespaceURI)
  97. al.Add (n);
  98. }
  99. return al.ToArray (typeof (XmlElement)) as XmlElement [];
  100. }
  101. }
  102. }