2 // XmlSignature.cs: Handles Xml Signature
5 // Sebastien Pouliot (spouliot@motus.com)
6 // Atsushi Enomoto (atsushi@ximian.com)
8 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
9 // (C) 2004 Novell Inc.
13 using System.Collections;
16 namespace System.Security.Cryptography.Xml {
18 // following the design of WSE
19 internal class XmlSignature {
21 public class ElementNames {
23 public const string CanonicalizationMethod = "CanonicalizationMethod";
24 public const string DigestMethod = "DigestMethod";
25 public const string DigestValue = "DigestValue";
26 public const string DSAKeyValue = "DSAKeyValue";
27 public const string HMACOutputLength = "HMACOutputLength";
28 public const string KeyInfo = "KeyInfo";
29 public const string KeyName = "KeyName";
30 public const string KeyValue = "KeyValue";
31 public const string Manifest = "Manifest";
32 public const string Object = "Object";
33 public const string Reference = "Reference";
35 // RetrievalMethod vs RetrievalElement -> BUG in MS Framework 1.0
36 public const string RetrievalMethod = "RetrievalElement";
38 public const string RetrievalMethod = "RetrievalMethod";
40 public const string RSAKeyValue = "RSAKeyValue";
41 public const string Signature = "Signature";
42 public const string SignatureMethod = "SignatureMethod";
43 public const string SignatureValue = "SignatureValue";
44 public const string SignedInfo = "SignedInfo";
45 public const string Transform = "Transform";
46 public const string Transforms = "Transforms";
47 public const string X509Data = "X509Data";
48 public const string X509IssuerSerial = "X509IssuerSerial";
49 public const string X509IssuerName = "X509IssuerName";
50 public const string X509SerialNumber = "X509SerialNumber";
51 public const string X509SKI = "X509SKI";
52 public const string X509SubjectName = "X509SubjectName";
53 public const string X509Certificate = "X509Certificate";
54 public const string X509CRL = "X509CRL";
56 public ElementNames () {}
59 public class AttributeNames {
61 public const string Algorithm = "Algorithm";
62 public const string Encoding = "Encoding";
63 public const string Id = "Id";
64 public const string MimeType = "MimeType";
65 public const string Type = "Type";
66 public const string URI = "URI";
68 public AttributeNames () {}
71 public class AlgorithmNamespaces {
72 public const string XmlDsigBase64Transform = "http://www.w3.org/2000/09/xmldsig#base64";
73 public const string XmlDsigC14NTransform = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
74 public const string XmlDsigC14NWithCommentsTransform = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments";
75 public const string XmlDsigEnvelopedSignatureTransform = "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
76 public const string XmlDsigXPathTransform = "http://www.w3.org/TR/1999/REC-xpath-19991116";
77 public const string XmlDsigXsltTransform = "http://www.w3.org/TR/1999/REC-xslt-19991116";
81 public const string Manifest = "http://www.w3.org/2000/09/xmldsig#Manifest";
84 public const string NamespaceURI = "http://www.w3.org/2000/09/xmldsig#";
85 public const string Prefix = "ds";
87 public XmlSignature ()
91 public static XmlElement GetChildElement (XmlElement xel, string element, string ns)
93 for (int i = 0; i < xel.ChildNodes.Count; i++) {
94 XmlNode n = xel.ChildNodes [i];
95 if (n.NodeType == XmlNodeType.Element && n.LocalName == element && n.NamespaceURI == ns)
96 return n as XmlElement;
101 public static string GetAttributeFromElement (XmlElement xel, string attribute, string element)
103 XmlElement el = GetChildElement (xel, element, XmlSignature.NamespaceURI);
104 return el != null ? el.GetAttribute (attribute) : null;
107 public static XmlElement [] GetChildElements (XmlElement xel, string element)
109 ArrayList al = new ArrayList ();
110 for (int i = 0; i < xel.ChildNodes.Count; i++) {
111 XmlNode n = xel.ChildNodes [i];
112 if (n.NodeType == XmlNodeType.Element && n.LocalName == element && n.NamespaceURI == XmlSignature.NamespaceURI)
115 return al.ToArray (typeof (XmlElement)) as XmlElement [];