public void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException("value"); } if ((value.LocalName != XmlSignature.ElementNames.SignedInfo) || (value.NamespaceURI != XmlSignature.NamespaceURI)) { throw new CryptographicException(); } id = GetAttribute(value, XmlSignature.AttributeNames.Id); c14nMethod = XmlSignature.GetAttributeFromElement(value, XmlSignature.AttributeNames.Algorithm, XmlSignature.ElementNames.CanonicalizationMethod); XmlElement sm = XmlSignature.GetChildElement(value, XmlSignature.ElementNames.SignatureMethod, XmlSignature.NamespaceURI); if (sm != null) { signatureMethod = sm.GetAttribute(XmlSignature.AttributeNames.Algorithm); XmlElement length = XmlSignature.GetChildElement(sm, XmlSignature.ElementNames.HMACOutputLength, XmlSignature.NamespaceURI); if (length != null) { signatureLength = length.InnerText; } } for (int i = 0; i < value.ChildNodes.Count; i++) { XmlNode n = value.ChildNodes [i]; if (n.NodeType == XmlNodeType.Element && n.LocalName == XmlSignature.ElementNames.Reference && n.NamespaceURI == XmlSignature.NamespaceURI) { Reference r = new Reference(); r.LoadXml((XmlElement)n); AddReference(r); } } element = value; }
public void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException("value"); } if ((value.LocalName != XmlSignature.ElementNames.Reference) || (value.NamespaceURI != XmlSignature.NamespaceURI)) { throw new CryptographicException(); } id = GetAttribute(value, XmlSignature.AttributeNames.Id); uri = GetAttribute(value, XmlSignature.AttributeNames.URI); type = GetAttribute(value, XmlSignature.AttributeNames.Type); // Note: order is important for validations XmlNodeList xnl = value.GetElementsByTagName(XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI); if ((xnl != null) && (xnl.Count > 0)) { Transform t = null; foreach (XmlNode xn in xnl) { string a = GetAttribute((XmlElement)xn, XmlSignature.AttributeNames.Algorithm); /* This code is useful for debugging in VS.NET because using CryptoConfig * (from MS mscorlib) would throw InvalidCastException because it's * Transform would come from MS System.Security.dll not Mono's. * switch (a) { * case "http://www.w3.org/2000/09/xmldsig#base64": * t = new XmlDsigBase64Transform (); * break; * case "http://www.w3.org/TR/2001/REC-xml-c14n-20010315": * t = new XmlDsigC14NTransform (); * break; * case "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments": * t = new XmlDsigC14NWithCommentsTransform (); * break; * case "http://www.w3.org/2000/09/xmldsig#enveloped-signature": * t = new XmlDsigEnvelopedSignatureTransform (); * break; * case "http://www.w3.org/TR/1999/REC-xpath-19991116": * t = new XmlDsigXPathTransform (); * break; * case "http://www.w3.org/TR/1999/REC-xslt-19991116": * t = new XmlDsigXsltTransform (); * break; * case "http://www.w3.org/2002/07/decrypt#XML": * t = new XmlDecryptionTransform (); * break; * default: * throw new NotSupportedException (); * } */ t = (Transform)CryptoConfig.CreateFromName(a); if (t == null) { throw new CryptographicException("Unknown transform {0}.", a); } if (xn.ChildNodes.Count > 0) { t.LoadInnerXml(xn.ChildNodes); } AddTransform(t); } } // get DigestMethod DigestMethod = XmlSignature.GetAttributeFromElement(value, XmlSignature.AttributeNames.Algorithm, XmlSignature.ElementNames.DigestMethod); // get DigestValue XmlElement dig = XmlSignature.GetChildElement(value, XmlSignature.ElementNames.DigestValue, XmlSignature.NamespaceURI); if (dig != null) { DigestValue = Convert.FromBase64String(dig.InnerText); } element = value; }