Example #1
0
        private void btnFirmar_Click(object sender, EventArgs e)
        {
            _firmaXades.PolicyIdentifier = txtIdentificadorPolitica.Text;
            _firmaXades.PolicyHash       = txtHashPolitica.Text;
            _firmaXades.PolicyUri        = txtURIPolitica.Text;

            if (string.IsNullOrEmpty(txtFichero.Text))
            {
                MessageBox.Show("Debe seleccionar un fichero para firmar.");
                return;
            }

            if (rbInternnallyDetached.Checked)
            {
                // TODO: gestionar correctamente los tipos MIME
                string mimeType = "application/" +
                                  System.IO.Path.GetExtension(txtFichero.Text).ToLower().Replace(".", "");

                _firmaXades.SetContentInternallyDetached(txtFichero.Text, mimeType);
            }
            else if (rbExternallyDetached.Checked)
            {
                _firmaXades.SetContentExternallyDetached(txtFichero.Text);
            }
            else if (rbEnveloped.Checked)
            {
                _firmaXades.SetContentEnveloped(txtFichero.Text);
            }

            _firmaXades.Sign(_firmaXades.SelectCertificate());

            MessageBox.Show("Firma completada, ahora puede Guardar la firma o ampliarla a Xades-T.", "Test firma XADES",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #2
0
        public Recepcion.respuestaSolicitud EnviarComprobante(String rutafirma, String xml)
        {
            Recepcion.respuestaSolicitud response = null;
            try
            {
                var        xmlDoc     = new XmlDocument();
                var        uidCert    = GetCertificateByPath(rutafirma, "Amira2019alaia");
                FirmaXades firmaXades = new FirmaXades(SignMethod.RSAwithSHA1, DigestMethod.SHA1);
                xmlDoc.Load(xml);

                xmlDoc.PreserveWhitespace = true;
                firmaXades.SetContentEnveloped(xmlDoc);
                firmaXades.Sign(uidCert, SignMethod.RSAwithSHA1);

                using (Recepcion.RecepcionComprobantesOfflineClient envio = new Recepcion.RecepcionComprobantesOfflineClient())
                {
                    response = envio.validarComprobante(System.Text.Encoding.UTF8.GetBytes(firmaXades.Document.InnerXml));
                    return(response);
                }
            }
            catch (Exception Ex)
            {
                return(response);
            }
        }
Example #3
0
        private void btnFirmar_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtFichero.Text))
            {
                MessageBox.Show("Debe seleccionar un fichero para firmar.");
                return;
            }

            if (rbInternnallyDetached.Checked)
            {
                string mimeType = MimeTypeInfo.GetMimeType(txtFichero.Text);

                EstablecerPolitica();

                _firmaXades.SetContentInternallyDetached(txtFichero.Text, mimeType);
            }
            else if (rbExternallyDetached.Checked)
            {
                _firmaXades.SetContentExternallyDetached(txtFichero.Text);
            }
            else if (rbEnveloped.Checked)
            {
                _firmaXades.SetContentEnveloped(txtFichero.Text);
            }

            SignMethod tipoMetodoFirma = ObtenerAlgoritmo();

            _firmaXades.Sign(_firmaXades.SelectCertificate(), tipoMetodoFirma);

            MessageBox.Show("Firma completada, ahora puede Guardar la firma o ampliarla a Xades-T.", "Test firma XADES",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #4
0
        private void btnGenerar_Click(object sender, EventArgs e)
        {
            FirmaXades firmaXades     = new FirmaXades();
            string     ficheroFactura = Application.StartupPath + "\\Facturae.xml";

            firmaXades.SetContentEnveloped(ficheroFactura);

            // PolĂ­tica de firma de factura-e 3.1
            firmaXades.PolicyIdentifier = "http://www.facturae.es/politica_de_firma_formato_facturae/politica_de_firma_formato_facturae_v3_1.pdf";
            firmaXades.PolicyHash       = "Ohixl6upD6av8N7pEvDABhEL6hM=";

            firmaXades.Sign(firmaXades.SelectCertificate());

            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                firmaXades.Save(saveFileDialog1.FileName);
                MessageBox.Show("Fichero guardado correctamente.");
            }
        }