Beispiel #1
0
        private void btnFirmar_Click(object sender, EventArgs e)
        {
            var outputPath          = txtOutputFile.Text;
            var selectedCertificate = GetSelectedCertificate();
            var selectedFormat      = GetSelectedSignatureFormat();
            var inputPath           = txtFileToSign.Text;
            var xpathToNodeToSign   = txtNodeToSign.Text ?? "";

            if (!"".Equals(xpathToNodeToSign))
            {
                if (!xpathToNodeToSign.StartsWith("#"))
                {
                    xpathToNodeToSign = "#" + xpathToNodeToSign;
                }
            }

            var howToSign =
                XmlDsigHelper.Sign(inputPath).Using(selectedCertificate).UsingFormat(selectedFormat)
                .IncludingCertificateInSignature().IncludeTimestamp(chkIncludeTimestamp.Checked)
                .NodeToSign(xpathToNodeToSign);

            if (chkAddProperty.Checked)
            {
                howToSign.WithProperty(txtPropertyName.Text, txtPropertyValue.Text, "http://xades.codeplex.com/#properties");
            }
            howToSign.SignToFile(outputPath);
            XmlDsigHelper.Verify(outputPath).Perform();

            MessageBox.Show(@"Signature created and verified successfully :)");
        }
Beispiel #2
0
        public void TestEnvelopedSign()
        {
            X509Certificate2 certificate = GetTestCertificate();
            XmlDocument      document    = XmlDsigHelper.Sign(_inputPath).Using(certificate).Enveloped().IncludingCertificateInSignature().SignAndGetXml();
            String           expected    = GetXmlStringFromFile(_filesBasePath + "OutputEnveloped.xml");

            Assert.AreEqual(expected, document.OuterXml);
        }
Beispiel #3
0
        private void btnValidate_Click(object sender, EventArgs e)
        {
            var results = XmlDsigHelper.Verify(txtFileToValidate.Text).PerformAndGetResults();

            txtOriginalXml.Text = results.OriginalDocument.OuterXml;
            txtTimestamp.Text   = results.Timestamp;
            txtCertificate.Text = results.SigningCertificate.Subject;
            MessageBox.Show(@"Signature verified!");
        }