当前位置: 首页>>代码示例>>C#>>正文


C# Reference.LoadXml方法代码示例

本文整理汇总了C#中System.Security.Cryptography.Xml.Reference.LoadXml方法的典型用法代码示例。如果您正苦于以下问题:C# Reference.LoadXml方法的具体用法?C# Reference.LoadXml怎么用?C# Reference.LoadXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.Xml.Reference的用法示例。


在下文中一共展示了Reference.LoadXml方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: KeepDocument

		public void KeepDocument ()
		{
			string result = @"<dsig:Reference URI="""" xmlns:dsig=""http://www.w3.org/2000/09/xmldsig#""><dsig:Transforms><dsig:Transform Algorithm=""http://www.w3.org/2000/09/xmldsig#enveloped-signature"" /></dsig:Transforms><dsig:DigestMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#sha1"" /><dsig:DigestValue>nDF2V/bzRd0VE3EwShWtsBzTEDc=</dsig:DigestValue></dsig:Reference>";

			XmlDocument doc = new XmlDocument ();
			doc.LoadXml (xml);
			XmlElement org = (XmlElement) doc.SelectSingleNode ("//*[local-name()='Reference']");
			Reference r = new Reference ();
			r.LoadXml (org);
			XmlElement el = r.GetXml ();
			Assert.AreEqual (doc, el.OwnerDocument);
			Assert.AreEqual (org, el);
			Assert.AreEqual (result, el.OuterXml);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:14,代码来源:ReferenceTest.cs

示例2: VerifySignature

        public static bool VerifySignature(Stream xmlStream, Stream signatureStream, out X509Certificate2 certificate)
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(signatureStream);

            SignedXml signedXml = new SignedXml();
            signedXml.LoadXml(xmlDocument.DocumentElement);
            certificate = signedXml.KeyInfo.OfType<KeyInfoX509Data>().SelectMany(c => c.Certificates.OfType<X509Certificate2>()).FirstOrDefault();

            foreach (Reference reference in signedXml.SignedInfo.References.ToArray())
            {
                Reference newReference = new Reference(xmlStream);
                newReference.LoadXml(reference.GetXml());
                signedXml.AddReference(newReference);
                signedXml.SignedInfo.References.Remove(reference);
            }

            return signedXml.CheckSignature();
        }
开发者ID:ywcsz,项目名称:modSIC,代码行数:19,代码来源:XmlSignatureHelper.cs

示例3: LoadXml

 public void LoadXml(XmlElement value)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     XmlElement element = value;
     if (!element.LocalName.Equals("SignedInfo"))
     {
         throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_InvalidElement"), "SignedInfo");
     }
     XmlNamespaceManager nsmgr = new XmlNamespaceManager(value.OwnerDocument.NameTable);
     nsmgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
     this.m_id = System.Security.Cryptography.Xml.Utils.GetAttribute(element, "Id", "http://www.w3.org/2000/09/xmldsig#");
     XmlElement element2 = element.SelectSingleNode("ds:CanonicalizationMethod", nsmgr) as XmlElement;
     if (element2 == null)
     {
         throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_InvalidElement"), "SignedInfo/CanonicalizationMethod");
     }
     this.m_canonicalizationMethod = System.Security.Cryptography.Xml.Utils.GetAttribute(element2, "Algorithm", "http://www.w3.org/2000/09/xmldsig#");
     this.m_canonicalizationMethodTransform = null;
     if (element2.ChildNodes.Count > 0)
     {
         this.CanonicalizationMethodObject.LoadInnerXml(element2.ChildNodes);
     }
     XmlElement element3 = element.SelectSingleNode("ds:SignatureMethod", nsmgr) as XmlElement;
     if (element3 == null)
     {
         throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_InvalidElement"), "SignedInfo/SignatureMethod");
     }
     this.m_signatureMethod = System.Security.Cryptography.Xml.Utils.GetAttribute(element3, "Algorithm", "http://www.w3.org/2000/09/xmldsig#");
     XmlElement element4 = element3.SelectSingleNode("ds:HMACOutputLength", nsmgr) as XmlElement;
     if (element4 != null)
     {
         this.m_signatureLength = element4.InnerXml;
     }
     this.m_references.Clear();
     XmlNodeList list = element.SelectNodes("ds:Reference", nsmgr);
     if (list != null)
     {
         foreach (XmlNode node in list)
         {
             XmlElement element5 = node as XmlElement;
             Reference reference = new Reference();
             this.AddReference(reference);
             reference.LoadXml(element5);
         }
     }
     this.m_cachedXml = element;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:50,代码来源:SignedInfo.cs

示例4: LoadXml

		public void LoadXml (XmlElement value) 
		{
			if (value == null)
				throw new ArgumentNullException ("value");

			if ((value.LocalName != XmlSignature.ElementNames.Manifest) || (value.NamespaceURI != XmlSignature.NamespaceURI))
				throw new CryptographicException ();

			id = GetAttribute (value, XmlSignature.AttributeNames.Id);

			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;
		}
开发者ID:Xipas,项目名称:Symplified.Auth,代码行数:22,代码来源:Manifest.cs

示例5: LoadXml

		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;
		}
开发者ID:Xipas,项目名称:Symplified.Auth,代码行数:32,代码来源:SignedInfo.cs

示例6: LoadXml

        public void LoadXml(XmlElement value) {
            if (value == null)
                throw new ArgumentNullException("value");

            // SignedInfo
            XmlElement signedInfoElement = value;
            if (!signedInfoElement.LocalName.Equals("SignedInfo"))
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_InvalidElement"), "SignedInfo");

            XmlNamespaceManager nsm = new XmlNamespaceManager(value.OwnerDocument.NameTable);
            nsm.AddNamespace("ds", SignedXml.XmlDsigNamespaceUrl);

            // Id attribute -- optional
            m_id = Utils.GetAttribute(signedInfoElement, "Id", SignedXml.XmlDsigNamespaceUrl);

            // CanonicalizationMethod -- must be present
            XmlElement canonicalizationMethodElement = signedInfoElement.SelectSingleNode("ds:CanonicalizationMethod", nsm) as XmlElement;
            if (canonicalizationMethodElement == null)
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_InvalidElement"),"SignedInfo/CanonicalizationMethod");
            m_canonicalizationMethod = Utils.GetAttribute(canonicalizationMethodElement, "Algorithm", SignedXml.XmlDsigNamespaceUrl);
            m_canonicalizationMethodTransform = null;
            if (canonicalizationMethodElement.ChildNodes.Count > 0)
                this.CanonicalizationMethodObject.LoadInnerXml(canonicalizationMethodElement.ChildNodes);

            // SignatureMethod -- must be present
            XmlElement signatureMethodElement = signedInfoElement.SelectSingleNode("ds:SignatureMethod", nsm) as XmlElement;
            if (signatureMethodElement == null)
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_InvalidElement"),"SignedInfo/SignatureMethod");
            m_signatureMethod = Utils.GetAttribute(signatureMethodElement, "Algorithm", SignedXml.XmlDsigNamespaceUrl);

            // Now get the output length if we are using a MAC algorithm
            XmlElement signatureLengthElement = signatureMethodElement.SelectSingleNode("ds:HMACOutputLength", nsm) as XmlElement;
            if (signatureLengthElement != null) 
                m_signatureLength = signatureLengthElement.InnerXml;

            // flush out any reference that was there
            m_references.Clear();

            XmlNodeList referenceNodes = signedInfoElement.SelectNodes("ds:Reference", nsm);
            if (referenceNodes != null) {
                foreach(XmlNode node in referenceNodes) {
                    XmlElement referenceElement = node as XmlElement;
                    Reference reference = new Reference();
                    AddReference(reference);
                    reference.LoadXml(referenceElement);
                }
            }

            // Save away the cached value
            m_cachedXml = signedInfoElement;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:51,代码来源:SignedInfo.cs


注:本文中的System.Security.Cryptography.Xml.Reference.LoadXml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。