XmlSignature.cs 3.5 KB

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