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


C# SignedXml.CheckSignature方法代码示例

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


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

示例1: ValidateLicenseXml

        public LicenseDetails ValidateLicenseXml(string xml)
        {
            var doc = new XmlDocument();
            using (TextReader reader = new StringReader(xml))
            {
                try
                {
                    doc.Load(reader);
                }
                catch
                {
                    throw new InvalidLicenseXmlException();
                }

                // Validate the xml's signature
                var signedXml = new SignedXml(doc);
                var nodeList = doc.GetElementsByTagName("Signature");
                if (nodeList.Count == 0)
                    throw new LicenseSignatureMissingException();

                signedXml.LoadXml((XmlElement) nodeList[0]);
                if (!signedXml.CheckSignature(_key))
                    throw new LicenseSignatureMismatchException();
            }

            // Deserialize the xml
            var deserializer = new XmlSerializer(typeof(LicenseDetails));
            using (TextReader reader = new StringReader(xml))
                return (LicenseDetails) deserializer.Deserialize(reader);
        }
开发者ID:KallDrexx,项目名称:ELiS,代码行数:30,代码来源:LicenseValidator.cs

示例2: VerifyXml

            public void VerifyXml(string xml)
            {
                var doc = LoadXmlDoc(xml);

                using (var rsa = new RSACryptoServiceProvider())
                {
                    rsa.FromXmlString(publicKey);

                    var nsMgr = new XmlNamespaceManager(doc.NameTable);
                    nsMgr.AddNamespace("sig", "http://www.w3.org/2000/09/xmldsig#");

                    var signedXml = new SignedXml(doc);
                    var signature = (XmlElement)doc.SelectSingleNode("//sig:Signature", nsMgr);
                    if (signature == null)
                    {
                        throw new Exception("Xml is invalid as it has no XML signature");
                    }
                    signedXml.LoadXml(signature);

                    if (!signedXml.CheckSignature(rsa))
                    {
                        throw new Exception("Xml is invalid as it failed signature check.");
                    }
                }
            }
开发者ID:Particular,项目名称:ServiceInsight,代码行数:25,代码来源:LicenseVerifier.cs

示例3: VerifyDigitalSignature

        /// <summary>
        /// Verifies the digital signature.
        /// </summary>
        /// <param name="digitalSignature"> The XML Digital Signature.</param>
        /// <param name="publicKey"> The RSA public key.</param>
        /// <returns> Returns true if valid, else false.</returns>
        public static bool VerifyDigitalSignature(XmlTextReader digitalSignature, RSA publicKey)
        {
            bool valid = false;
            try
            {
                // Load license file into XmlDocument
                XmlDocument doc = new XmlDocument();
                doc.Load(digitalSignature);

                // Load Signature Element
                SignedXml verifier = new SignedXml(doc);
                verifier.LoadXml(doc.GetElementsByTagName("Signature")[0] as XmlElement);

                // Validate license.
                if ( verifier.CheckSignature(publicKey) )
                {
                    valid = true;
                }
                else
                {
                    valid = false;
                }
            }
            catch
            {
                valid = false;
            }

            return valid;
        }
开发者ID:molekilla,项目名称:Ecyware_GreenBlue_Inspector,代码行数:36,代码来源:DigitalSignatureVerifier.cs

示例4: VerifyXml

        // Verify the signature of an XML file against an asymmetric
        // algorithm and return the result.
        public static Boolean VerifyXml(XmlDocument Doc, RSA Key)
        {
            // Check arguments.
            if (Doc == null)
                throw new ArgumentException("Doc");
            if (Key == null)
                throw new ArgumentException("Key");

            // Create a new SignedXml object and pass it
            // the XML document class.
            SignedXml signedXml = new SignedXml(Doc);

            // Find the "Signature" node and create a new
            // XmlNodeList object.
            XmlNodeList nodeList = Doc.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.");
            }

            //One Sig per document
            if (nodeList.Count >= 2)
            {
                throw new CryptographicException("Verification failed: More that one signature was found for the document.");
            }

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

            // Check the signature and return the result.
            return signedXml.CheckSignature(Key);
        }
开发者ID:vpereira,项目名称:sadan,代码行数:36,代码来源:Program.cs

示例5: IsValid

        public bool IsValid() {
            XmlNamespaceManager manager = new XmlNamespaceManager(XmlDoc.NameTable);
            manager.AddNamespace("ds", SignedXml.XmlDsigNamespaceUrl);
            XmlNodeList nodeList = XmlDoc.SelectNodes("//ds:Signature", manager);

            SignedXml signedXml = new SignedXml(XmlDoc);
            signedXml.LoadXml((XmlElement)nodeList[0]);
            return signedXml.CheckSignature(DecrypingCertificate, true);
        }
开发者ID:RunLola,项目名称:Practices.IdentityProvider,代码行数:9,代码来源:AuthnResponse.cs

示例6: Constructor_XmlDocument

		public void Constructor_XmlDocument () 
		{
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml (signature);
			XmlNodeList xnl = doc.GetElementsByTagName ("Signature", SignedXml.XmlDsigNamespaceUrl);
			XmlElement xel = (XmlElement) xnl [0];

			SignedXml sx = new SignedXml (doc);
			sx.LoadXml (doc.DocumentElement);
			Assert.IsTrue (sx.CheckSignature (), "CheckSignature");
		}
开发者ID:vargaz,项目名称:mono,代码行数:11,代码来源:SignedXmlTest.cs

示例7: CheckSignedXmlDocument

        public static Boolean CheckSignedXmlDocument(Stream sourceXmlFile)
        {
            // Carico il documento XML
            XmlDocument doc = new XmlDocument();
            doc.Load(sourceXmlFile);

            // Verifico la firma
            SignedXml sigs = new SignedXml(doc);
            XmlNodeList sigElems = doc.GetElementsByTagName("Signature");
            sigs.LoadXml((XmlElement)sigElems[0]);
            return (sigs.CheckSignature());
        }
开发者ID:stijnbrouwers,项目名称:PnP-Sites-Core,代码行数:12,代码来源:SecureXml.cs

示例8: XmlIsValid

        public static bool XmlIsValid(XmlDocument signedXml,
                                AsymmetricAlgorithm key)
        {
            var nsm = new XmlNamespaceManager(new NameTable());
            nsm.AddNamespace("dsig", SignedXml.XmlDsigNamespaceUrl);

            var signatureGenerator = new SignedXml(signedXml);
            var signatureNode = signedXml
                    .SelectSingleNode("//dsig:Signature", nsm);
            signatureGenerator.LoadXml((XmlElement)signatureNode);

            return signatureGenerator.CheckSignature(key);
        }
开发者ID:huoxudong125,项目名称:HQF.Tutorial.Encryption,代码行数:13,代码来源:SignAndVerify.cs

示例9: IsValid

		public bool IsValid(KeyInfo keyInfo)
		{
			SignedXml xml = new SignedXml(_doc);

			XmlNodeList nodeList = _doc.GetElementsByTagName("Signature");

			xml.LoadXml((XmlElement)nodeList[0]);

			xml.KeyInfo = keyInfo;

            xml.Resolver = null;
            
            return xml.CheckSignature();
		}
开发者ID:codingbat,项目名称:BandCamp,代码行数:14,代码来源:LicenseValidator.cs

示例10: Main

        static void Main(string[] args)
        {
            var xml = "<xml><a ID=\"foo\"><content>foo-content</content><Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\" /></a><a ID=\"bar\"><content>bar-content</content><Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\" /></a></xml>";

            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(xml);

            var key = new RSACryptoServiceProvider();

            var sign = new SignedXml(xmlDocument);
            var reference2 = new Reference("#bar");
            reference2.AddTransform(new XmlDsigEnvelopedSignatureTransform());
            sign.AddReference(reference2);
            sign.SigningKey = key;
            sign.ComputeSignature();
            var barNode = (XmlElement)xmlDocument.SelectSingleNode("//*[@ID=\"bar\"]");
            barNode.AppendChild(xmlDocument.ImportNode(sign.GetXml(), true));

            var barSignature = barNode.ChildNodes.OfType<XmlElement>()
                .Single(x => x.LocalName == "Signature" && x.HasChildNodes);

            WriteLine("== Xml document ==");
            WriteLine(xmlDocument.OuterXml);
            WriteLine();

            var verify = new SignedXml(xmlDocument);
            verify.LoadXml(barSignature);
            WriteLine("Check Signature: " + verify.CheckSignature(key));

            WriteLine();
            WriteLine("Reloading SignedXml and fixing signature index...");
            verify.LoadXml(barSignature);
            FixSignatureIndex(verify, barSignature);
            WriteLine("Check Signature: " + verify.CheckSignature(key));

            ReadLine();
        }
开发者ID:AndersAbel,项目名称:XmlDsigEnvelopedFix,代码行数:37,代码来源:Program.cs

示例11: IsResponseValid

        public bool IsResponseValid(XmlDocument xDoc)
        {
            XmlNamespaceManager manager = new XmlNamespaceManager(xDoc.NameTable);
            manager.AddNamespace("ds", SignedXml.XmlDsigNamespaceUrl);
            XmlNodeList nodeList = xDoc.SelectNodes("//ds:Signature", manager);

            SignedXml signedXml = new SignedXml(xDoc);
            signedXml.LoadXml((XmlElement)nodeList[0]);

            X509Certificate2 cSigningCertificate = new X509Certificate2();

            cSigningCertificate.Import(HttpContext.Current.Server.MapPath(".") + @"\Certificates\SignCertFromCentrify.cer");

            return signedXml.CheckSignature(cSigningCertificate, true);
        }
开发者ID:centrify,项目名称:CentrifySAMLSDK_CS,代码行数:15,代码来源:SAML_Interface.cs

示例12: IsValid

        public bool IsValid()
        {
            bool status = false;

            XmlNamespaceManager manager = new XmlNamespaceManager(xmlDoc.NameTable);
            manager.AddNamespace("ds", SignedXml.XmlDsigNamespaceUrl);
            XmlNodeList nodeList = xmlDoc.SelectNodes("//ds:Signature", manager);

            SignedXml signedXml = new SignedXml(xmlDoc);
            signedXml.LoadXml((XmlElement)nodeList[0]);
            status = signedXml.CheckSignature(certificateHelper.cert, true);
            if (!status)
                return false;
            return status;
        }
开发者ID:mzbac,项目名称:SAMLSPLib,代码行数:15,代码来源:SAMLResponseHelper.cs

示例13: 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

示例14: 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

示例15: GeneratedXmlIsCorrectlySigned

        public void GeneratedXmlIsCorrectlySigned()
        {
            var key = new RSACryptoServiceProvider();
            var generator = new LicenseGenerator(key);

            var rawXml = generator.GenerateSignedXml(new LicenseDetails());

            var doc = new XmlDocument();
            TextReader reader = new StringReader(rawXml);
            doc.Load(reader);

            var signedXml = new SignedXml(doc);
            var nodeList = doc.GetElementsByTagName("Signature");
            signedXml.LoadXml((XmlElement)nodeList[0]);
            var result = signedXml.CheckSignature(key);
            Assert.IsTrue(result, "Verification of xml signature failed");
        }
开发者ID:KallDrexx,项目名称:ELiS,代码行数:17,代码来源:LicenseGeneratorTests.cs


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