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


C# SignedXml.GetIdElement方法代码示例

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


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

示例1: GetIdElement_Null

		public void GetIdElement_Null ()
		{
			SignedXml sign = new SignedXml ();
			Assert.IsNull (sign.GetIdElement (null, "value"));
			Assert.IsNull (sign.GetIdElement (new XmlDocument (), null));
		}
开发者ID:vargaz,项目名称:mono,代码行数:6,代码来源:SignedXmlTest.cs

示例2: ValidateSignedInfo

        private static void ValidateSignedInfo(SignedXml signedXml, XmlElement xmlElement)
        {
            if(signedXml.SignedInfo.References.Count == 0)
            {
                throw new InvalidSignatureException("No reference found in Xml signature, it doesn't validate the Xml data.");
            }

            if(signedXml.SignedInfo.References.Count != 1)
            {
                throw new InvalidSignatureException("Multiple references for Xml signatures are not allowed.");
            }

            var reference = (Reference)signedXml.SignedInfo.References[0];
            var id = reference.Uri.Substring(1);

            var idElement = signedXml.GetIdElement(xmlElement.OwnerDocument, id);
            
            if(idElement != xmlElement)
            {
                throw new InvalidSignatureException("Incorrect reference on Xml signature. The reference must be to the root element of the element containing the signature.");
            }

            foreach (Transform transform in reference.TransformChain)
            {
                if (!allowedTransforms.Contains(transform.Algorithm))
                {
                    throw new InvalidSignatureException(
                        "Transform \"" + transform.Algorithm + "\" found in Xml signature SHOULD NOT be used with SAML2.");
                }
            }
        }
开发者ID:victorayub,项目名称:authservices,代码行数:31,代码来源:XmlHelpers.cs

示例3: GetIdElement

		// adapted from http://bugzilla.ximian.com/show_bug.cgi?id=52084
		public void GetIdElement () 
		{
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml (signature);

			SignedXml v1 = new SignedXml ();
			v1.LoadXml (doc.DocumentElement);
			Assert.IsTrue (v1.CheckSignature (), "CheckSignature");

			XmlElement xel = v1.GetIdElement (doc, "MyObjectId");
			Assert.IsTrue (xel.InnerXml.StartsWith ("<ObjectListTag"), "GetIdElement");
		}
开发者ID:vargaz,项目名称:mono,代码行数:13,代码来源:SignedXmlTest.cs

示例4: VerifySignature

        /// <summary>
        /// Verifies the signature.
        /// </summary>
        /// <param name="xml">The XML.</param>
        /// <returns>The issuer certificate</returns>
        protected virtual X509Certificate2 VerifySignature(XElement xml)
        {
            Contract.Requires(xml != null);
            Contract.Ensures(Contract.Result<X509Certificate2>() != null);

            if ((Configuration == null) || (Configuration.IssuerTokenResolver == null))
            {
                throw new SecurityTokenException("No issuer token resolver configured");
            }

            var xmlElement = xml.ToXmlElement();
            var signedXml = new SignedXml(xmlElement);
            
            // find signature
            XmlNodeList nodeList = xmlElement.GetElementsByTagName("Signature");

            // throw an exception if no signature was found.
            if (nodeList.Count <= 0)
            {
                throw new CryptographicException("Verification failed: No Signature was found in the document.");
            }

            // throw an exception if more than one signature was found.
            if (nodeList.Count > 1)
            {
                throw new CryptographicException("Verification failed: More that one signature was found for the document.");
            }

            // load the <signature> node.  
            signedXml.LoadXml((XmlElement)nodeList[0]);

            // resolve the issuer certificate
            byte[] thumbprint = Convert.FromBase64String(GetIssuerThumbprint(signedXml));
            var identifier = new X509ThumbprintKeyIdentifierClause(thumbprint);
            var issuerKey = Configuration.IssuerTokenResolver.ResolveToken(identifier) as X509SecurityToken;


            // check the signature
            var referenceUri = ((Reference)signedXml.SignedInfo.References[0]).Uri;

            if (!signedXml.CheckSignature(issuerKey.Certificate, true)
                || (referenceUri != "" && signedXml.GetIdElement(xmlElement.OwnerDocument, referenceUri) != xmlElement))
            {
                throw new CryptographicException("Signature verification failed");
            }

            if (issuerKey.Certificate != null)
            {
                return issuerKey.Certificate;
            }
            else
            {
                throw new CryptographicException("No issuer certificate found");
            }
        }
开发者ID:IdentityModel,项目名称:Thinktecture.IdentityModel.v1,代码行数:60,代码来源:AccessSecurityTokenHandler.cs


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