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