Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        private void btnFirmar_Click(object sender, EventArgs e)
        {
            FirmaXades firmaXades = new FirmaXades();
            string     ficheroXml = Application.StartupPath + "\\xsdBOE-A-2011-13169_ex_XAdES_Internally_detached.xml";

            XmlDocument documento = new XmlDocument();

            documento.Load(ficheroXml);

            firmaXades.SetContentInternallyDetached(documento, "CONTENT-12ef114d-ac6c-4da3-8caf-50379ed13698", "text/xml");

            Dictionary <string, string> namespaces = new Dictionary <string, string>();

            namespaces.Add("enidoc", "http://administracionelectronica.gob.es/ENI/XSD/v1.0/documento-e");
            namespaces.Add("enidocmeta", "http://administracionelectronica.gob.es/ENI/XSD/v1.0/documento-e/metadatos");
            namespaces.Add("enids", "http://administracionelectronica.gob.es/ENI/XSD/v1.0/firma");
            namespaces.Add("enifile", "http://administracionelectronica.gob.es/ENI/XSD/v1.0/documento-e/contenido");

            firmaXades.SetSignatureDestination("enidoc:documento/enids:firmas/enids:firma/enids:ContenidoFirma/enids:FirmaConCertificado", namespaces);

            firmaXades.Sign(firmaXades.SelectCertificate());

            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                using (FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create))
                {
                    firmaXades.Save(fs);
                }

                MessageBox.Show("Fichero guardado correctamente.");
            }
        }
Beispiel #5
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.");
            }
        }