Пример #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);
        }
Пример #2
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);
        }