2 // XmlSignature.cs: Handles Xml Signature
5 // Sebastien Pouliot (spouliot@motus.com)
6 // Atsushi Enomoto (atsushi@ximian.com)
7 // Tim Coleman (tim@timcoleman.com)
9 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
10 // Copyright (C) Tim Coleman, 2004
11 // (C) 2004 Novell Inc.
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.Collections;
39 namespace System.Security.Cryptography.Xml {
41 // following the design of WSE
42 internal class XmlSignature {
44 public class ElementNames {
46 public const string CanonicalizationMethod = "CanonicalizationMethod";
47 public const string DigestMethod = "DigestMethod";
48 public const string DigestValue = "DigestValue";
49 public const string DSAKeyValue = "DSAKeyValue";
50 public const string EncryptedKey = "EncryptedKey";
51 public const string HMACOutputLength = "HMACOutputLength";
52 public const string KeyInfo = "KeyInfo";
53 public const string KeyName = "KeyName";
54 public const string KeyValue = "KeyValue";
55 public const string Manifest = "Manifest";
56 public const string Object = "Object";
57 public const string Reference = "Reference";
58 public const string RetrievalMethod = "RetrievalMethod";
59 public const string RSAKeyValue = "RSAKeyValue";
60 public const string Signature = "Signature";
61 public const string SignatureMethod = "SignatureMethod";
62 public const string SignatureValue = "SignatureValue";
63 public const string SignedInfo = "SignedInfo";
64 public const string Transform = "Transform";
65 public const string Transforms = "Transforms";
66 public const string X509Data = "X509Data";
67 public const string X509IssuerSerial = "X509IssuerSerial";
68 public const string X509IssuerName = "X509IssuerName";
69 public const string X509SerialNumber = "X509SerialNumber";
70 public const string X509SKI = "X509SKI";
71 public const string X509SubjectName = "X509SubjectName";
72 public const string X509Certificate = "X509Certificate";
73 public const string X509CRL = "X509CRL";
75 public ElementNames () {}
78 public class AttributeNames {
80 public const string Algorithm = "Algorithm";
81 public const string Encoding = "Encoding";
82 public const string Id = "Id";
83 public const string MimeType = "MimeType";
84 public const string Type = "Type";
85 public const string URI = "URI";
87 public AttributeNames () {}
91 public const string Manifest = "http://www.w3.org/2000/09/xmldsig#Manifest";
94 public const string NamespaceURI = "http://www.w3.org/2000/09/xmldsig#";
95 public const string Prefix = "ds";
97 public XmlSignature ()
101 public static XmlElement GetChildElement (XmlElement xel, string element, string ns)
103 for (int i = 0; i < xel.ChildNodes.Count; i++) {
104 XmlNode n = xel.ChildNodes [i];
105 if (n.NodeType == XmlNodeType.Element && n.LocalName == element && n.NamespaceURI == ns)
106 return n as XmlElement;
111 public static string GetAttributeFromElement (XmlElement xel, string attribute, string element)
113 XmlElement el = GetChildElement (xel, element, XmlSignature.NamespaceURI);
114 return el != null ? el.GetAttribute (attribute) : null;
117 public static XmlElement [] GetChildElements (XmlElement xel, string element)
119 ArrayList al = new ArrayList ();
120 for (int i = 0; i < xel.ChildNodes.Count; i++) {
121 XmlNode n = xel.ChildNodes [i];
122 if (n.NodeType == XmlNodeType.Element && n.LocalName == element && n.NamespaceURI == XmlSignature.NamespaceURI)
125 return al.ToArray (typeof (XmlElement)) as XmlElement [];