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


C# XmlDocument.Sign方法代码示例

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


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

示例1: SignXml

        public static string SignXml(string xml, bool includeKeyInfo = false, bool preserveWhitespace = true)
        {
            var xmlDoc = new XmlDocument { PreserveWhitespace = preserveWhitespace };
            xmlDoc.LoadXml(xml);

            xmlDoc.Sign(TestCert, includeKeyInfo);

            return xmlDoc.OuterXml;
        }        
开发者ID:arvinsuresh,项目名称:authservices,代码行数:9,代码来源:SignedXmlHelper.cs

示例2: SignXml

        public static string SignXml(string xml)
        {
            var xmlDoc = new XmlDocument { PreserveWhitespace = true };
            xmlDoc.LoadXml(xml);

            xmlDoc.Sign(TestCert);

            return xmlDoc.OuterXml;
        }
开发者ID:sebastianallard,项目名称:authservices,代码行数:9,代码来源:SignedXmlHelper.cs

示例3: XmlDocumentExtensions_Sign

        public void XmlDocumentExtensions_Sign()
        {
            var xmlDoc = new XmlDocument();
            xmlDoc.LoadXml("<root><content>Some Content</content></root>");

            xmlDoc.Sign(TestCert);

            var signature = xmlDoc.DocumentElement["Signature", SignedXml.XmlDsigNamespaceUrl];

            var signedXml = new SignedXml(xmlDoc);

            signedXml.LoadXml(signature);

            signedXml.CheckSignature(TestCert, true).Should().BeTrue();
        }
开发者ID:pallu,项目名称:authservices,代码行数:15,代码来源:XmlDocumentExtensionsTests.cs

示例4: Index

        public ActionResult Index()
        {
            var request = XElement.Load(Request.InputStream);

            var artifact = request
                .Element(Saml2Namespaces.SoapEnvelope + "Body")
                .Element(Saml2Namespaces.Saml2P + "ArtifactResolve")
                .Element(Saml2Namespaces.Saml2P + "Artifact")
                .Value;

            var requestId = request
                .Element(Saml2Namespaces.SoapEnvelope + "Body")
                .Element(Saml2Namespaces.Saml2P + "ArtifactResolve")
                .Attribute("ID").Value;

            var binaryArtifact = Convert.FromBase64String(artifact);

            ISaml2Message message = null;
            if(!Saml2ArtifactBinding.PendingMessages.TryRemove(binaryArtifact, out message))
            {
                throw new InvalidOperationException("Unknown artifact");
            }

            var xml = message.ToXml();

            if(message.SigningCertificate != null)
            {
                var xmlDoc = new XmlDocument()
                {
                    PreserveWhitespace = true
                };

                xmlDoc.LoadXml(xml);
                xmlDoc.Sign(message.SigningCertificate, true);
                xml = xmlDoc.OuterXml;
            }

            var response = string.Format(
                CultureInfo.InvariantCulture,
                ResponseFormatString,
                new Saml2Id().Value,
                requestId,
                DateTime.UtcNow.ToSaml2DateTimeString(),
                xml);

            return Content(response);
        }
开发者ID:nate-impartner,项目名称:authservices,代码行数:47,代码来源:ArtifactResolveController.cs

示例5: ToXmlString

        public static string ToXmlString(this MetadataBase metadata, X509Certificate2 signingCertificate)
        {
            var serializer = ExtendedMetadataSerializer.WriterInstance;

            var xmlDoc = new XmlDocument();
            using (var xmlWriter = xmlDoc.CreateNavigator().AppendChild())
            {
                serializer.WriteMetadata(xmlWriter, metadata);
            }

            if (signingCertificate != null)
            {
                xmlDoc.Sign(signingCertificate, true);
            }

            return xmlDoc.OuterXml;
        }
开发者ID:CDHDeveloper,项目名称:authservices,代码行数:17,代码来源:MetadatabaseExtensions.cs

示例6: XmlDocumentExtensions_Sign

        public void XmlDocumentExtensions_Sign()
        {
            var xmlDoc = new XmlDocument();
            xmlDoc.LoadXml("<root ID=\"rootElementId\"><content>Some Content</content></root>");

            xmlDoc.Sign(TestCert);

            var signature = xmlDoc.DocumentElement["Signature", SignedXml.XmlDsigNamespaceUrl];

            signature["SignedInfo", SignedXml.XmlDsigNamespaceUrl]
                ["Reference", SignedXml.XmlDsigNamespaceUrl].Attributes["URI"].Value
                .Should().Be("#rootElementId");

            var signedXml = new SignedXml(xmlDoc);
            signedXml.LoadXml(signature);
            signedXml.CheckSignature(TestCert, true).Should().BeTrue();
        }
开发者ID:arvinsuresh,项目名称:authservices,代码行数:17,代码来源:XmlDocumentExtensionsTests.cs

示例7: Bind

        public override CommandResult Bind(ISaml2Message message)
        {
            if(message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var xml = message.ToXml();
            if(message.SigningCertificate != null)
            {
                var xmlDoc = new XmlDocument()
                {
                    PreserveWhitespace = true
                };

                xmlDoc.LoadXml(xml);
                xmlDoc.Sign(message.SigningCertificate, true);
                xml = xmlDoc.OuterXml;
            }

            var encodedXml = Convert.ToBase64String(Encoding.UTF8.GetBytes(xml));

            var relayStateHtml = string.IsNullOrEmpty(message.RelayState) ? null
                : string.Format(CultureInfo.InvariantCulture, PostHtmlRelayStateFormatString, message.RelayState);

            var cr = new CommandResult()
            {
                ContentType = "text/html",
                Content = String.Format(
                    CultureInfo.InvariantCulture,
                    PostHtmlFormatString,
                    message.DestinationUrl,
                    relayStateHtml,
                    message.MessageName,
                    encodedXml)
            };

            return cr;
        }
开发者ID:arvinsuresh,项目名称:authservices,代码行数:39,代码来源:Saml2PostBinding.cs

示例8: CreateXmlDocument

        private void CreateXmlDocument()
        {
            var xml = new XmlDocument();
            xml.AppendChild(xml.CreateXmlDeclaration("1.0", null, null));

            var responseElement = xml.CreateElement("saml2p", "Response", Saml2Namespaces.Saml2PName);

            if (DestinationUrl != null)
            {
                responseElement.SetAttributeNode("Destination", "").Value = DestinationUrl.ToString();
            }

            responseElement.SetAttributeNode("ID", "").Value = id.Value;
            responseElement.SetAttributeNode("Version", "").Value = "2.0";
            responseElement.SetAttributeNode("IssueInstant", "").Value =
                DateTime.UtcNow.ToSaml2DateTimeString();
            if (InResponseTo != null)
            {
                responseElement.SetAttributeNode("InResponseTo", "").Value = InResponseTo.Value;
            }
            xml.AppendChild(responseElement);

            var issuerElement = xml.CreateElement("saml2", "Issuer", Saml2Namespaces.Saml2Name);
            issuerElement.InnerText = issuer.Id;
            responseElement.AppendChild(issuerElement);

            var statusElement = xml.CreateElement("saml2p", "Status", Saml2Namespaces.Saml2PName);
            var statusCodeElement = xml.CreateElement("saml2p", "StatusCode", Saml2Namespaces.Saml2PName);
            statusCodeElement.SetAttributeNode("Value", "").Value = StatusCodeHelper.FromCode(Status);
            statusElement.AppendChild(statusCodeElement);
            responseElement.AppendChild(statusElement);

            foreach (var ci in claimsIdentities)
            {
                responseElement.AppendChild(xml.ReadNode(
                    ci.ToSaml2Assertion(issuer).ToXElement().CreateReader()));
            }

            xmlDocument = xml;

            xml.Sign(issuerCertificate);
        }
开发者ID:FutuRETI,项目名称:WebApplicationSP,代码行数:42,代码来源:Saml2Response.cs

示例9: ToXml

        /// <summary>
        /// Serializes the message into wellformed Xml.
        /// </summary>
        /// <returns>string containing the Xml data.</returns>
        public override string ToXml()
        {
            if (SigningCertificate == null)
            {
                return ToXElement().ToString();
            }
            else
            {
                var xml = ToXElement();

                var xmlDocument = new XmlDocument();
                using (var xmlReader = xml.CreateReader())
                {
                    xmlDocument.Load(xmlReader);
                }
                switch (SigningAlgorithm)
                {
                    case AuthenticationRequestSigningAlgorithm.Sha1:
                        xmlDocument.Sign(SigningCertificate);
                        break;
                    case AuthenticationRequestSigningAlgorithm.Sha256:
                        xmlDocument.Sign256(SigningCertificate, false);
                        break;
                }

                return xmlDocument.OuterXml;
            }
        }
开发者ID:baguit,项目名称:authservices,代码行数:32,代码来源:Saml2AuthenticationRequest.cs

示例10: ToXml

        /// <summary>
        /// Serializes the message into wellformed Xml.
        /// </summary>
        /// <returns>string containing the Xml data.</returns>
        public override string ToXml()
        {
            if (SigningCertificate == null)
            {
                return ToXElement().ToString();
            }
            else
            {
                var xml = ToXElement();

                var xmlDocument = new XmlDocument();
                using (var xmlReader = xml.CreateReader())
                {
                    xmlDocument.Load(xmlReader);
                }

                xmlDocument.Sign(SigningCertificate);

                return xmlDocument.OuterXml;
            }
        }
开发者ID:lario,项目名称:authservices,代码行数:25,代码来源:Saml2AuthenticationRequest.cs

示例11: XmlDocumentExtensions_Sign_Nullcheck_Cert

        public void XmlDocumentExtensions_Sign_Nullcheck_Cert()
        {
            XmlDocument xd = new XmlDocument();
            Action a = () => xd.Sign(null);

            a.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("cert");
        }
开发者ID:arvinsuresh,项目名称:authservices,代码行数:7,代码来源:XmlDocumentExtensionsTests.cs


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