Пример #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);
        }
Пример #2
0
        private void btnFirmar_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtFichero.Text))
            {
                MessageBox.Show("Debe seleccionar un fichero para firmar.");
                return;
            }

            XadesService        xadesService = new XadesService();
            SignatureParameters parametros   = ObtenerParametrosFirma();

            if (rbInternnallyDetached.Checked)
            {
                parametros.SignaturePolicyInfo = ObtenerPolitica();
                parametros.SignaturePackaging  = SignaturePackaging.INTERNALLY_DETACHED;
                parametros.DataFormat          = new DataFormat();
                parametros.DataFormat.MimeType = MimeTypeInfo.GetMimeType(txtFichero.Text);
            }
            else if (rbExternallyDetached.Checked)
            {
                parametros.SignaturePackaging = SignaturePackaging.EXTERNALLY_DETACHED;
                parametros.ExternalContentUri = txtFichero.Text;
            }
            else if (rbEnveloped.Checked)
            {
                parametros.SignaturePackaging = SignaturePackaging.ENVELOPED;
            }
            else if (rbEnveloping.Checked)
            {
                parametros.SignaturePackaging = SignaturePackaging.ENVELOPING;
            }

            using (parametros.Signer = new Signer(CertUtil.SelectCertificate()))
            {
                if (parametros.SignaturePackaging != SignaturePackaging.EXTERNALLY_DETACHED)
                {
                    using (FileStream fs = new FileStream(txtFichero.Text, FileMode.Open))
                    {
                        _signatureDocument = xadesService.Sign(fs, parametros);
                    }
                }
                else
                {
                    _signatureDocument = xadesService.Sign(null, parametros);
                }
            }

            MessageBox.Show("Firma completada, ahora puede Guardar la firma o ampliarla a Xades-T.", "Test firma XADES",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Пример #3
0
        private void btnFirmar_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtFichero.Text))
            {
                MessageBox.Show("You must select a file to sign.");
                return;
            }

            XadesService        xadesService = new XadesService();
            SignatureParameters parametros   = ObtenerParametrosFirma();

            if (rbInternnallyDetached.Checked)
            {
                parametros.SignaturePolicyInfo = ObtenerPolitica();
                parametros.SignaturePackaging  = SignaturePackaging.INTERNALLY_DETACHED;
                parametros.InputMimeType       = MimeTypeInfo.GetMimeType(txtFichero.Text);
            }
            else if (rbExternallyDetached.Checked)
            {
                parametros.SignaturePackaging = SignaturePackaging.EXTERNALLY_DETACHED;
                parametros.ExternalContentUri = txtFichero.Text;
            }
            else if (rbEnveloped.Checked)
            {
                parametros.SignaturePackaging = SignaturePackaging.ENVELOPED;
            }
            else if (rbEnveloping.Checked)
            {
                parametros.SignaturePackaging = SignaturePackaging.ENVELOPING;
            }

            using (parametros.Signer = new Signer(SelectCertificate()))
            {
                if (parametros.SignaturePackaging != SignaturePackaging.EXTERNALLY_DETACHED)
                {
                    using (FileStream fs = new FileStream(txtFichero.Text, FileMode.Open))
                    {
                        _signatureDocument = xadesService.Sign(fs, parametros);
                    }
                }
                else
                {
                    _signatureDocument = xadesService.Sign(null, parametros);
                }
            }

            MessageBox.Show("Signature completed, you can now Save the signature or extend it to Xades-T or Xades-XL.", "Test firma XADES",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }