예제 #1
0
        private void BtnCertificado_Click(object sender, RoutedEventArgs e)
        {
            consola.Text = "";

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.PreserveWhitespace = true;
            xmlDoc.LoadXml(txtClaro.Text);

            var store = new X509Store(StoreLocation.CurrentUser);

            store.Open(OpenFlags.ReadOnly);
            var cert = store.Certificates.Find(X509FindType.FindBySubjectName, txtCertificado.Text, false)[0];

            store.Close();
            ESign.Encrypt(xmlDoc, "creditcard", cert);
            txtSalida.Text = xmlDoc.InnerXml;

            XmlDocument xmlDoc2 = new XmlDocument();

            xmlDoc2.PreserveWhitespace = true;
            xmlDoc2.LoadXml(txtSalida.Text);
            ESign.Decrypt(xmlDoc2);
            WriteLine(xmlDoc2.InnerXml);
        }
예제 #2
0
        private void BtnASimetrico_Click(object sender, RoutedEventArgs e)
        {
            consola.Text = "";

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.PreserveWhitespace = true;
            xmlDoc.LoadXml(txtClaro.Text);
            CspParameters cspParams = new CspParameters();

            cspParams.KeyContainerName = "XML_ENC_RSA_KEY";
            RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(cspParams);

            ESign.Encrypt(xmlDoc, txtEtiqueta.Text, "EncryptedElement1", rsaKey, "rsaKey");
            txtSalida.Text = xmlDoc.InnerXml;

            XmlDocument xmlDoc2 = new XmlDocument();

            xmlDoc2.PreserveWhitespace = true;
            xmlDoc2.LoadXml(txtSalida.Text);

            ESign.Decrypt(xmlDoc2, rsaKey, "rsaKey");
            WriteLine(xmlDoc2.InnerXml);
            rsaKey.Clear();
        }
예제 #3
0
        private void DesEncSim(SymmetricAlgorithm key)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.PreserveWhitespace = true;
            xmlDoc.LoadXml(txtSalida.Text);
            ESign.Decrypt(xmlDoc, key);
            WriteLine(xmlDoc.InnerXml);
        }
예제 #4
0
        private void EncSim(SymmetricAlgorithm key)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.PreserveWhitespace = true;
            xmlDoc.LoadXml(txtClaro.Text);
            ESign.Encrypt(xmlDoc, txtEtiqueta.Text, key);
            txtSalida.Text = xmlDoc.InnerXml;
        }
예제 #5
0
        private void BtnXMLVerifica_Click(object sender, RoutedEventArgs e)
        {
            consola.Text = "";

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.PreserveWhitespace = true;
            xmlDoc.LoadXml(txtSalida.Text);
            CspParameters cspParams = new CspParameters();

            cspParams.KeyContainerName = "XML_ENC_RSA_KEY";
            RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(cspParams);

            WriteLine($"The XML signature is {(ESign.VerifyXml(xmlDoc, rsaKey) ? "" : "not ")}valid.");
        }
예제 #6
0
        private void BtnXMLFirma_Click(object sender, RoutedEventArgs e)
        {
            consola.Text = "";

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.PreserveWhitespace = true;
            xmlDoc.LoadXml(txtClaro.Text);
            CspParameters cspParams = new CspParameters();

            cspParams.KeyContainerName = "XML_ENC_RSA_KEY";
            RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(cspParams);

            ESign.SignXml(xmlDoc, rsaKey);
            txtSalida.Text = xmlDoc.InnerXml;
        }