public void FirmarServerPDFButton_T_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. //string path = Environment.CurrentDirectory; //FileStream fs = File.OpenRead(path + "\\resources\\exampleSign.pdf"); Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); // En algunos casos, por ejemplo en el arranque de la aplicación puede ser interesante // Comprobar que efectivamente el servidor de firma está disponible System.Console.Write(clienteViafirma.ping("Prueba Conexión") + "\n"); // Enviamos a firmar el documento al servidor y obtenemos el identificador final de la firma. idFirma = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.pdf", datos_a_firmar, Global.ALIAS, Global.PASS_CERT, typeFile.PDF, typeFormatSign.PDF_PKCS7_T); // Generamos la url a la página que gestiona la comunicación con Viafirma. // Uri url = new Uri(HttpContext.Current.Request.Url, HttpContext.Current.Response.ApplyAppPathModifier("~/ResultadoFirmaServidor.aspx")); // Log.Debug("Redireccionado al usuario a: " + url); // Guardamos el Id de Firma HttpContext.Current.Session["idFirma"] = idFirma; // Redirecciona a la url // HttpContext.Current.Response.Redirect(url.AbsoluteUri); }
protected void verifySignButton_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient viafirmaClient = ViafirmaClientFactory.GetInstance(); //Recuperamos el identificador de la firma String signId = Request.Form["signId"]; // Instaciamos la clase encargada de añadir los parámetros verificationSignatureRequest verificationSignatureRequest = VerifyUtil.newVerify(); // Vamos añadiendo los parámetros al listado // SignatureStandard String signatureStandardKey = VerifyParams.SIGNATURE_STANDARD_KEY; String signatureStandardValue = VerifyParams.PADES_SIGNATURE_STANDARD; // Añadimos el parámetro SignatureStandard VerifyUtil.AddParameter(verificationSignatureRequest, signatureStandardKey, signatureStandardValue); // TypeSign String typeSignKey = VerifyParams.TYPE_SIGN_KEY; String typeSignValue = VerifyParams.ENVELOPED_TYPE_SIGN; // Añadimos el parámetro TypeSign VerifyUtil.AddParameter(verificationSignatureRequest, typeSignKey, typeSignValue); // Sign ID String signIdKey = VerifyParams.SIGNATURE_ID_KEY; String signIdValue = signId; // Añadimos el parámetro TypeSign VerifyUtil.AddParameter(verificationSignatureRequest, signIdKey, signIdValue); signatureVerification = viafirmaClient.verifySignature(verificationSignatureRequest); }
public void Download_Click(Object sender, EventArgs e) { LinkButton btn = sender as LinkButton; string signatureID = Convert.ToString(btn.CommandArgument); // Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento original. documento docu = clienteViafirma.getOriginalDocument(signatureID); // Y lo ponemos a disposicion del usario Stream stream = null; try { // Open the file into a stream. stream = new MemoryStream(docu.datos); // Total bytes to read: long bytesToRead = stream.Length; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + "documentoOriginal.xml"); // Read the bytes from the stream in small portions. while (bytesToRead > 0) { // Make sure the client is still connected. if (Response.IsClientConnected) { // Read the data into the buffer and write into the // output stream. byte[] buffer = new Byte[10000]; int length = stream.Read(buffer, 0, 10000); Response.OutputStream.Write(buffer, 0, length); Response.Flush(); // We have already read some bytes.. need to read // only the remaining. bytesToRead = bytesToRead - length; } else { // Get out of the loop, if user is not connected anymore.. bytesToRead = -1; } } } catch (Exception ex) { Response.Write(ex.Message); // An error occurred.. } finally { if (stream != null) { stream.Close(); } } }
public void FirmarUserPDF_POLICY_SELLO_GENERICO_Button_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. //string path = Environment.CurrentDirectory; //FileStream fs = File.OpenRead(path + "\\resources\\exampleSign.pdf"); Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); //Obtengo la imagen a estampar Stream stampImage = assembly.GetManifestResourceStream(Global.DEMO_STAMPER_PATH); byte[] image = new byte[stampImage.Length]; stampImage.Read(image, 0, image.Length); String imageB64 = System.Convert.ToBase64String(image); // Enviamos a firmar el documento //Creamos el objeto documento con los datos a firmar documento doc = new documento(); doc.nombre = "PDF_SELLOIMAGEN.pdf"; doc.datos = datos_a_firmar; doc.typeFormatSign = typeFormatSign.PAdES_BASIC; doc.tipo = typeFile.PDF; // En algunos casos, por ejemplo en el arranque de la aplicación puede ser interesante // Comprobar que efectivamente el servidor de firma está disponible System.Console.Write(clienteViafirma.ping("Prueba Conexión") + "\n"); //Creamos la politica de firma policy pol = PolicyUtil.newPolicy(typeFormatSign.PAdES_BASIC, typeSign.ATTACHED); PolicyUtil.AddParameter(pol, PolicyParams.DIGITAL_SIGN_PAGE, "1"); //creamos el rectangle rectangle r = PolicyUtil.newRectangle(140, 200, 100, 50); PolicyUtil.AddParameter(pol, PolicyParams.DIGITAL_SIGN_RECTANGLE, PolicyUtil.rectangleToJson(r)); // Registramos el documento que deseamos firmar. Obteniendo un identificador temporal. // Este identificador temporal no es necesario que sea almacenado ya que sólo tiene validez durante el proceso de firma. string idTemporalFirma = clienteViafirma.PrepareSignWithPolicy(pol, doc); System.Console.Write("idTemporalFirma: " + idTemporalFirma); //Logica del ejemplo para descagar el fichero con la extension correcta Session["extension"] = ".pdf"; // Iniciamos el proceso de firma redireccionando al usuario a Viafirma.. // Esto redireccionará al usuario a Viafirma para la firma del documento con el // identificador de firma indicado. clienteViafirma.Sign(idTemporalFirma); }
protected void ComprobarCertificadoAliasButton_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient viafirmaClient = ViafirmaClientFactory.GetInstance(); //Recuperamos el alias introducido en el input text String alias = Request.Form["aliasCert"]; validationInfo = viafirmaClient.checkCertificateByAlias(alias); }
public void Autenticar_Click(object sender, EventArgs e) { // Iniciamos el proceso de autenticar redireccionando el usuario a Viafirma. ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); policy pol = new policy(); clienteViafirma.AuthWithPolicy(pol); }
public void FirmarServerPDFButton_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. //string path = Environment.CurrentDirectory; //FileStream fs = File.OpenRead(path + "\\resources\\exampleSign.pdf"); Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); //byte[] datos_a_firmar = File.ReadAllBytes(@"C:\598MB.pdf"); //FileStream strm = new FileStream(@"C:\598MB.pdf", FileMode.Open, FileAccess.Read, FileShare.Read, 1024, FileOptions.Asynchronous); //datos_a_firmar_grande = new byte[strm.Length]; //IAsyncResult result = strm.BeginRead(datos_a_firmar_grande, 0, datos_a_firmar_grande.Length, new AsyncCallback(CompleteRead), strm); // En algunos casos, por ejemplo en el arranque de la aplicación puede ser interesante // Comprobar que efectivamente el servidor de firma está disponible System.Console.Write(clienteViafirma.ping("Prueba Conexión") + "\n"); // Enviamos a firmar el documento al servidor y obtenemos el identificador final de la firma. //idFirma = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.pdf", datos_a_firmar, Global.ALIAS, Global.PASS_CERT, typeFile.PDF, typeFormatSign.PDF_PKCS7); //Creamos el objeto documento con los datos a firmar documento doc = new documento(); doc.nombre = "PDF_ejemplo.pdf"; doc.datos = datos_a_firmar; doc.typeFormatSign = typeFormatSign.PAdES_LTV; doc.tipo = typeFile.PDF; //Creamos la politica de firma policy pol = PolicyUtil.newPolicy(typeFormatSign.PAdES_LTV, typeSign.ATTACHED); idFirma = clienteViafirma.SignByServerWithPolicy(pol, doc, Global.ALIAS, Global.PASS_CERT); // Generamos la url a la página que gestiona la comunicación con Viafirma. // Uri url = new Uri(HttpContext.Current.Request.Url, HttpContext.Current.Response.ApplyAppPathModifier("~/ResultadoFirmaServidor.aspx")); // Log.Debug("Redireccionado al usuario a: " + url); // Guardamos el Id de Firma HttpContext.Current.Session["idFirma"] = idFirma; // Redirecciona a la url // HttpContext.Current.Response.Redirect(url.AbsoluteUri); }
protected void ComprobarCertificadoPemButton_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient viafirmaClient = ViafirmaClientFactory.GetInstance(); //Recuperamos el pem introducido en el textarea String pem = Request.Form["pem"]; byte[] pemBytes = Encoding.ASCII.GetBytes(pem); certificateResponse = viafirmaClient.verifyCertificate(pemBytes); }
public void GetCustodiadoButton_Click(object sender, EventArgs e) { // Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el id String id = (string)Session["id"]; // Recuperamos el documento custodiado. byte[] documento = clienteViafirma.getDocumentoCustodiado(id); // Y lo ponemos a disposicion del usario try { // Open the file into a stream. stream = new System.IO.MemoryStream(documento); // Total bytes to read: long bytesToRead = stream.Length; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + "documentoCustodiado.xml"); // Read the bytes from the stream in small portions. while (bytesToRead > 0) { // Make sure the client is still connected. if (Response.IsClientConnected) { // Read the data into the buffer and write into the // output stream. byte[] buffer = new Byte[10000]; int length = stream.Read(buffer, 0, 10000); Response.OutputStream.Write(buffer, 0, length); Response.Flush(); // We have already read some bytes.. need to read // only the remaining. bytesToRead = bytesToRead - length; } else { // Get out of the loop, if user is not connected anymore.. bytesToRead = -1; } } } catch (Exception ex) { Response.Write(ex.Message); // An error occurred.. } finally { if (stream != null) { stream.Close(); } } }
public async void Autenticar_ClickAsync(object sender, EventArgs e) { // Iniciamos el proceso de autenticar redireccionando el usuario a Viafirma. ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); AuthOperationRequest request = new AuthOperationRequest(); request.AutoSend = true; request.SessionId = HttpContext.Current.Session.SessionID; desktopInvocation = await clienteViafirma.PrepareAuthForDirectDesktopAsync(request); }
protected async void Page_Load(object sender, EventArgs e) { operationId = Request.QueryString["operationId"]; string sessionId = HttpContext.Current.Session.SessionID; SignatureResponse response = new SignatureResponse(); List <SignatureResponse> list = new List <SignatureResponse>(); SignatureResponse signatureResponse = await ViafirmaClientFactory.GetInstance().GetSignatureResponse(operationId, sessionId); list.Add(signatureResponse); DataListResult.DataSource = list; DataListResult.DataBind(); }
public void IniciarCustodiadoButton_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_XML_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); // Enviamos a firmar el documento al servidor y obtenemos el identificador final de la firma. idFirma = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.xml", datos_a_firmar, Global.ALIAS, Global.PASS_CERT, typeFile.XML, typeFormatSign.XADES_EPES_ENVELOPED); Session.Add("id", idFirma); }
public async void Firmar_ClickAsync(object sender, EventArgs e) { // Iniciamos el proceso de autenticar redireccionando el usuario a Viafirma. ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); AuthOperationRequest authRequest = new AuthOperationRequest(); authRequest.AutoSend = true; string sessionId = HttpContext.Current.Session.SessionID; string[] languages = HttpContext.Current.Request.UserLanguages; string locale = languages[0]; //Creamos la politica de firma policy pol = PolicyUtil.newPolicy(typeFormatSign.PAdES_BASIC, typeSign.ATTACHED); //Creamos el rectangle rectangle r = PolicyUtil.newRectangle(40, 10, 550, 75); //Seteamos la politica PolicyUtil.AddParameter(pol, PolicyParams.DIGITAL_SIGN_PAGE, "1"); PolicyUtil.AddParameter(pol, PolicyParams.DIGITAL_SIGN_RECTANGLE, PolicyUtil.rectangleToJson(r)); PolicyUtil.AddParameter(pol, PolicyParams.DIGITAL_SIGN_STAMPER_HIDE_STATUS, "true"); PolicyUtil.AddParameter(pol, PolicyParams.DIGITAL_SIGN_STAMPER_TEXT, "Firmado por [CN] con DNI [SERIALNUMBER]\ntrabajador de [O] en el departamento de [OU]"); PolicyUtil.AddParameter(pol, PolicyParams.DIGITAL_SIGN_STAMPER_TYPE, "QR-BAR-H"); PolicyUtil.AddParameter(pol, PolicyParams.DIGITAL_SIGN_STAMPER_ROTATION_ANGLE, "90"); // Recuperamos el documento a firmar. Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); OperationFile file = new OperationFile(); file.Filename = "example.pdf"; file.Base64Content = System.Convert.ToBase64String(datos_a_firmar); file.Policy = pol; List <OperationFile> files = new List <OperationFile>(); files.Add(file); desktopInvocation = await clienteViafirma.PrepareSignatureForDirectDesktopAsync(authRequest, files, sessionId, locale); System.Console.Write("OperationId: " + desktopInvocation.OperationId); }
public async void Autenticar_SSL_ClickAsync(object sender, EventArgs e) { string callbackUrl = ""; string currentUrl = HttpContext.Current.Request.Url.AbsoluteUri; int index = currentUrl.LastIndexOf("/"); if (index > 0) { callbackUrl = currentUrl.Substring(0, index) + "/exampleSSLClientAuthResult.aspx"; Console.Write("destination url: " + callbackUrl); } // Iniciamos el proceso de autenticar redireccionando el usuario a Viafirma. ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); sslAuthOperation = await clienteViafirma.PrepareSSLClientAuthAsync(callbackUrl); }
public void signByClient(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); //Obtengo el certificado con el cual voy a firmar Stream certificate = assembly.GetManifestResourceStream(Global.DEMO_P12_PATH); String certificatePass = "******"; // Enviamos a firmar el documento //Creamos el objeto documento con los datos a firmar documento doc = new documento(); doc.nombre = "clientSigned.pdf"; doc.datos = datos_a_firmar; doc.typeFormatSign = typeFormatSign.PAdES_BASIC; doc.tipo = typeFile.PDF; // En algunos casos, por ejemplo en el arranque de la aplicación puede ser interesante // Comprobar que efectivamente el servidor de firma está disponible System.Console.Write(clienteViafirma.ping("Prueba Conexión") + "\n"); //Creamos la politica de firma policy pol = PolicyUtil.newPolicy(typeFormatSign.PAdES_BASIC, typeSign.ENVELOPED); //PolicyUtil.AddParameter(pol, PolicyParams.SIGNATURE_ALGORITHM, "SHA1withRSA"); //PolicyUtil.AddParameter(pol, PolicyParams.DIGEST_METHOD, "SHA1"); //Logica del ejemplo para descagar el fichero con la extension correcta Session["extension"] = ".pdf"; //Hacemos la llamada a la firma en cliente signId = clienteViafirma.SignByClient(certificate, certificatePass, pol, doc); // Guardamos el Id de Firma HttpContext.Current.Session["signId"] = signId; }
public void FirmarUserCADES_DETACHED(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_CADES_T_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); // Enviamos a firmar el documento //Creamos el objeto documento con los datos a firmar documento doc = new documento(); doc.nombre = "documento.CADES"; doc.datos = datos_a_firmar; doc.typeFormatSign = typeFormatSign.CAdES_T; doc.tipo = typeFile.doc; // En algunos casos, por ejemplo en el arranque de la aplicación puede ser interesante // Comprobar que efectivamente el servidor de firma está disponible System.Console.Write(clienteViafirma.ping("Prueba Conexión") + "\n"); //Creamos la politica de firma policy pol = PolicyUtil.newPolicy(typeFormatSign.CAdES_T, typeSign.DETACHED); // Registramos el documento que deseamos firmar. Obteniendo un identificador temporal. // Este identificador temporal no es necesario que sea almacenado ya que sólo tiene validez durante el proceso de firma. string idTemporalFirma = clienteViafirma.PrepareSignWithPolicy(pol, doc); System.Console.Write("idTemporalFirma: " + idTemporalFirma); //Logica del ejemplo para descagar el fichero con la extension correcta Session["extension"] = ".CADES"; // Iniciamos el proceso de firma redireccionando al usuario a Viafirma.. // Esto redireccionará al usuario a Viafirma para la firma del documento con el // identificador de firma indicado. clienteViafirma.Sign(idTemporalFirma); }
public void ComprobarNoValidoButton_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); // Enviamos a firmar el documento al servidor y nos devuelve el identificador de la firma. idFirma = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.pdf", datos_a_firmar, Global.ALIAS, Global.PASS_CERT, typeFile.PDF, typeFormatSign.PDF_PKCS7); // Y comprobamos el documento original que no esta firmado para forzar q no sea valido. info = clienteViafirma.checkSignedDocumentValidityByFileType(datos_a_firmar, typeFormatSign.PDF_PKCS7); }
public void ComprobarNoValidoButton_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. string path = Environment.CurrentDirectory; Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); // Enviamos a firmar el documento al servidor y nos devuelve el identificador de la firma. String idFirma = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.pdf", datos_a_firmar, Global.ALIAS, Global.PASS_CERT, typeFile.PDF, typeFormatSign.PAdES_EPES); byte[] firmado1 = clienteViafirma.getDocumentoCustodiado(idFirma); //String idFirma2 = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.pdf", firmado1, Global.ALIAS, Global.PASS_CERT, typeFile.PDF, typeFormatSign.PAdES_EPES); //byte[] firmado2 = clienteViafirma.getDocumentoCustodiado(idFirma2); //String idFirma3 = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.pdf", firmado2, Global.ALIAS, Global.PASS_CERT, typeFile.PDF, typeFormatSign.PAdES_EPES); //byte[] firmado3 = clienteViafirma.getDocumentoCustodiado(idFirma3); // Y comprobamos el documento original que no esta firmado para forzar q no sea valido. firmaInfoViafirma infoFirma = clienteViafirma.checkSignedDocumentValidityByFileType(firmado1, typeFormatSign.PAdES_EPES); if (infoFirma.signed) { if (infoFirma.otherSigners == null) { //Solo tenemos la firma representada por infoFirma int numeroDeFirmas = 1; } else { //El numero de firmas es el numero de otros firmantes más el representado por infoFirma int numeroDeFirmas = infoFirma.otherSigners.Length + 1; } } else { int numeroDeFirmas = 0; } }
public void FirmarServerXMLButton_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_XML_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); // Enviamos a firmar el documento // En algunos casos, por ejemplo en el arranque de la aplicación puede ser interesante // Comprobar que efectivamente el servidor de firma está disponible System.Console.Write(clienteViafirma.ping("Prueba Conexión") + "\n"); //Creamos el objeto documento con los datos a firmar documento doc = new documento(); doc.nombre = "prueba.xml"; doc.datos = datos_a_firmar; doc.typeFormatSign = typeFormatSign.XADES_EPES_ENVELOPED; doc.tipo = typeFile.XML; //Creamos la politica de firma policy pol = PolicyUtil.newPolicy(typeFormatSign.XADES_EPES_ENVELOPED, typeSign.ENVELOPED); // Enviamos a firmar el documento al servidor y nos devuelve el identificador de la firma. idFirma = clienteViafirma.SignByServerWithPolicy(pol, doc, Global.ALIAS, Global.PASS_CERT); // Generamos la url a la página que gestiona la comunicación con Viafirma. //Uri url = new Uri(HttpContext.Current.Request.Url, HttpContext.Current.Response.ApplyAppPathModifier("~/ResultadoFirmaServidor.aspx")); //Log.Debug("Redireccionado al usuario a: " + url); // Guardamos el Id de Firma HttpContext.Current.Session["idFirma"] = idFirma; // Redirecciona a la url //HttpContext.Current.Response.Redirect(url.AbsoluteUri); }
public void ComprobarValidoButton_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_XML_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); // Enviamos a firmar el documento al servidor y nos devuelve el identificador de la firma. String idFirma = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.xml", datos_a_firmar, Global.ALIAS, Global.PASS_CERT, typeFile.XML, typeFormatSign.XADES_EPES_ENVELOPED); // Recuperamos el elemento firmado byte[] documento = clienteViafirma.getDocumentoCustodiado(idFirma); // Y comprobamos su validez infoFirma = clienteViafirma.checkDocumentSigned(documento, idFirma); }
public void GetFirmaButton_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. string path = Environment.CurrentDirectory; FileStream fs = File.OpenRead(path + "\\resources\\prueba.xml"); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); // Enviamos a firmar el documento al servidor y nos devuelve el identificador de la firma. String idFirma = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.xml", datos_a_firmar, Global.ALIAS, Global.PASS_CERT, typeFile.XML, typeFormatSign.XADES_EPES_ENVELOPED); // Recuperamos el elemento firmado byte[] documento = clienteViafirma.getDocumentoCustodiado(idFirma); // Y comprobamos su validez //infoFirma = clienteViafirma.getSignInfo; }
protected void FirmarLotesUserButton_Click(object sender, EventArgs e) { // Recuperamos el documento a firmar. Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_XML_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH); byte[] datos_a_firmar_pdf = new byte[fs.Length]; fs.Read(datos_a_firmar_pdf, 0, datos_a_firmar_pdf.Length); // Enviamos a firmar el documento ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // En algunos casos, por ejemplo en el arranque de la aplicación puede ser interesante // Comprobar que efectivamente el servidor de firma está disponible System.Console.Write(clienteViafirma.ping("Prueba Conexión") + "\n"); // Generamos un id temporal de lote para añadir documentos en él string idLote = clienteViafirma.iniciarFirmaEnLotes(typeFormatSign.XADES_EPES_ENVELOPED); System.Console.Write("idTemporalLote: " + idLote); // Añadimos un documento para firmar clienteViafirma.addDocumentoFirmaEnLote(idLote, "DocumentoEjemplo1.txt", typeFile.XML, datos_a_firmar); // Añadimos otro documento para firmar clienteViafirma.addDocumentoFirmaEnLote(idLote, "DocumentoEjemplo2.txt", typeFile.XML, datos_a_firmar); // Añadimos otro documento para firmar clienteViafirma.addDocumentoFirmaEnLote(idLote, "DocumentoEjemplo3.txt", typeFile.PDF, datos_a_firmar_pdf); // Añadimos otro documento para firmar clienteViafirma.addDocumentoFirmaEnLote(idLote, "DocumentoEjemplo4.txt", typeFile.PDF, datos_a_firmar_pdf); //Logica del ejemplo para no mostrar el boton de multifirma Session["multi"] = null; //Logica del ejemplo para descagar el fichero con la extension correcta Session["extension"] = ".xml"; // Firmamos clienteViafirma.Sign(idLote); }
public void GetOriginalDocumentIdsButton_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos los documentos a firmar. Assembly assembly = Assembly.GetExecutingAssembly(); Stream fsPDF = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH); byte[] datos_a_firmarPDF = new byte[fsPDF.Length]; fsPDF.Read(datos_a_firmarPDF, 0, datos_a_firmarPDF.Length); Stream fsXML = assembly.GetManifestResourceStream(Global.DEMO_FILE_XML_PATH); byte[] datos_a_firmarXML = new byte[fsXML.Length]; fsXML.Read(datos_a_firmarXML, 0, datos_a_firmarXML.Length); Stream fsTXT = assembly.GetManifestResourceStream(Global.DEMO_FILE_TXT_PATH); byte[] datos_a_firmarTXT = new byte[fsTXT.Length]; fsTXT.Read(datos_a_firmarTXT, 0, datos_a_firmarTXT.Length); // Creamos el lote: string idLote = clienteViafirma.iniciarFirmaEnLotes(typeFormatSign.XADES_EPES_ENVELOPED); // Agregamos los documentos al lote: clienteViafirma.addDocumentoFirmaEnLote(idLote, "LoteEjemplo1.pdf", typeFile.PDF, datos_a_firmarPDF); clienteViafirma.addDocumentoFirmaEnLote(idLote, "LoteEjemplo2.xml", typeFile.XML, datos_a_firmarXML); clienteViafirma.addDocumentoFirmaEnLote(idLote, "LoteEjemplo3.txt", typeFile.TXT, datos_a_firmarTXT); // Y enviamos a firmar el lote de documentos al servidor y obtenemos el identificador final de la firma. string id = clienteViafirma.signByServerEnLotes(idLote, Global.ALIAS, Global.PASS_CERT); string[] listadoIds = clienteViafirma.getOriginalDocumentIds(id); docuList = new List <documento>(); foreach (string idOrig in listadoIds) { documento doc = clienteViafirma.getOriginalDocument(idOrig); docuList.Add(doc); } }
public void FirmarUserXMLButton_Click(object sender, EventArgs e) { Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_XML_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); string originalHash = System.Convert.ToBase64String(datos_a_firmar); try { ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); string idFirma; //Creamos el objeto documento con los datos a firmar documento doc = new documento(); doc.nombre = "prueba.xml"; doc.datos = Encoding.ASCII.GetBytes(originalHash); doc.typeFormatSign = typeFormatSign.XADES_EPES_ENVELOPED; doc.tipo = typeFile.hash; //Creamos la politica de firma policy pol = PolicyUtil.newPolicy(typeFormatSign.XADES_EPES_ENVELOPED, typeSign.ENVELOPED); // Registramos el documento que deseamos firmar. Obteniendo un identificador temporal. // Este identificador temporal no es necesario que sea almacenado ya que sólo tiene validez durante el proceso de firma. idFirma = clienteViafirma.PrepareSignWithPolicy(pol, doc); //Logica del ejemplo para descagar el fichero con la extension correcta Session["extension"] = ".xml"; clienteViafirma.Sign(idFirma); } catch (Exception ex) { Console.Write(ex.StackTrace); } }
public void MultiSign_OnClick(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. string path = Environment.CurrentDirectory; FileStream fs = File.OpenRead(path + "\\resources\\prueba.xml"); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); // Enviamos a firmar el documento // En algunos casos, por ejemplo en el arranque de la aplicación puede ser interesante // Comprobar que efectivamente el servidor de firma está disponible System.Console.Write(clienteViafirma.ping("Prueba Conexión") + "\n"); // Registramos el documento que deseamos firmar. Obteniendo un identificador temporal. // Este identificador temporal no es necesario que sea almacenado ya que sólo tiene validez durante el proceso de firma. String idFirma; if (Request["idMultifirma"] != null) { idFirma = Request["idMultifirma"]; Session.Add("idMultifirma", idFirma); } idFirma = ViafirmaClientFactory.GetInstance().PrepareFirmaWithTypeFileAndFormatSign("FicheroEjemplo.xml", typeFile.XML, typeFormatSign.XADES_EPES_ENVELOPED, datos_a_firmar); idFirma = ViafirmaClientFactory.GetInstance().enabledMultiSign(idFirma); Session.Add("idMultifirma", idFirma); System.Console.Write("idTemporalFirma: " + idFirma); // Iniciamos el proceso de firma redireccionando al usuario a Viafirma.. // Esto redireccionará al usuario a Viafirma para la firma del documento con el // identificador de firma indicado. clienteViafirma.Sign(idFirma); }
protected void FirmarLotesServerButton_Click(object sender, EventArgs e) { // Recuperamos la instancia de Viafirma ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. //string path = Environment.CurrentDirectory; //FileStream fs = File.OpenRead(path + "\\resources\\exampleSign.pdf"); Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); // En algunos casos, por ejemplo en el arranque de la aplicación puede ser interesante // Comprobar que efectivamente el servidor de firma está disponible System.Console.Write(clienteViafirma.ping("Prueba Conexión") + "\n"); // Generamos un id temporal de lote para añadir documentos en él string idLote = clienteViafirma.iniciarFirmaEnLotes(typeFormatSign.XADES_EPES_ENVELOPED); System.Console.Write("idTemporalLote: " + idLote); // Añadimos un documento para firmar clienteViafirma.addDocumentoFirmaEnLote(idLote, "DocumentoEjemplo1.PDF", typeFile.PDF, datos_a_firmar); // Añadimos otro documento para firmar clienteViafirma.addDocumentoFirmaEnLote(idLote, "DocumentoEjemplo2.PDF", typeFile.PDF, datos_a_firmar); // Enviamos a firmar el lote de documentos al servidor y obtenemos el identificador final de la firma. idFirma = clienteViafirma.signByServerEnLotes(idLote, Global.ALIAS, Global.PASS_CERT); // Generamos la url a la página que gestiona la comunicación con Viafirma. // Uri url = new Uri(HttpContext.Current.Request.Url, HttpContext.Current.Response.ApplyAppPathModifier("~/ResultadoFirmaServidor.aspx")); // Log.Debug("Redireccionado al usuario a: " + url); // Guardamos el Id de Firma HttpContext.Current.Session["idFirma"] = idFirma; // Redirecciona a la url // HttpContext.Current.Response.Redirect(url.AbsoluteUri); }
public void FirmarUserCadesTDetached_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos los documentos a firmar. //Docx de ejemplo Assembly assembly = Assembly.GetExecutingAssembly(); Stream fsdocx = assembly.GetManifestResourceStream(Global.DEMO_CADES_T_PATH); byte[] datos_a_firmarDocx = new byte[fsdocx.Length]; fsdocx.Read(datos_a_firmarDocx, 0, datos_a_firmarDocx.Length); //XML de ejemplo Stream fsxml = assembly.GetManifestResourceStream(Global.DEMO_FILE_XML_PATH); byte[] datos_a_firmarXml = new byte[fsdocx.Length]; fsxml.Read(datos_a_firmarXml, 0, datos_a_firmarXml.Length); //Creamos el objeto documento del docx con los datos a firmar en CAdES_T documento docx = new documento(); docx.nombre = "firmaDocx.CAdES"; docx.datos = datos_a_firmarDocx; docx.typeFormatSign = typeFormatSign.CAdES_T; docx.tipo = typeFile.doc; //Creamos el objeto documento del xml con los datos a firmar en XAdES_T documento xml = new documento(); xml.nombre = "firmaXml.XAdES"; xml.datos = datos_a_firmarXml; xml.typeFormatSign = typeFormatSign.XADES_T_ENVELOPED; xml.tipo = typeFile.xlm; // En algunos casos, por ejemplo en el arranque de la aplicación puede ser interesante // Comprobar que efectivamente el servidor de firma está disponible System.Console.Write(clienteViafirma.ping("Prueba Conexión") + "\n"); // Registramos los documento que deseamos firmar en un listado. List <string> idsFirma = new List <string>(); //Creamos la politica de firma del docx en CAdES policy pol = PolicyUtil.newPolicy(typeFormatSign.CAdES_T, typeSign.DETACHED); // Registramos el documento que deseamos firmar. Obteniendo un identificador temporal. // Este identificador temporal no es necesario que sea almacenado ya que sólo tiene validez durante el proceso de firma. string idTemporalFirmaCAdES = clienteViafirma.PrepareSignWithPolicy(pol, docx); //Creamos la politica de firma del xml en XAdES pol = PolicyUtil.newPolicy(typeFormatSign.XADES_T_ENVELOPED, typeSign.DETACHED); // Registramos el documento que deseamos firmar. Obteniendo un identificador temporal. // Este identificador temporal no es necesario que sea almacenado ya que sólo tiene validez durante el proceso de firma. string idTemporalFirmaXAdES = clienteViafirma.PrepareSignWithPolicy(pol, xml); //Añadimos los ids temporales de las firmas que hemos preparado idsFirma.Add(idTemporalFirmaCAdES); idsFirma.Add(idTemporalFirmaXAdES); // Iniciamos el proceso de firma redireccionando al usuario a Viafirma.. // Esto redireccionará al usuario para la firma de los documentos // con una sola intervención del usuario. clienteViafirma.solicitarFirmasIndependientes(idsFirma.ToArray()); }
public void GenerarQRButton_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_XML_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); // Firmamos el documento en el servidor y nos devuelve el identificador de la firma. string idFirma = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.xml", datos_a_firmar, Global.ALIAS, Global.PASS_CERT, typeFile.XML, typeFormatSign.XADES_EPES_ENVELOPED); byte [] reciboQR = clienteViafirma.buildInfoQRBarCode(idFirma); System.IO.Stream stream = null; try { // Open the file into a stream. stream = new System.IO.MemoryStream(reciboQR); // Total bytes to read: long bytesToRead = stream.Length; Response.ContentType = "image/png"; Response.AddHeader("Content-Disposition", "attachment; filename=" + "reciboQR.png"); // Read the bytes from the stream in small portions. while (bytesToRead > 0) { // Make sure the client is still connected. if (Response.IsClientConnected) { // Read the data into the buffer and write into the // output stream. byte[] buffer = new Byte[10000]; int length = stream.Read(buffer, 0, 10000); Response.OutputStream.Write(buffer, 0, length); Response.Flush(); // We have already read some bytes.. need to read // only the remaining. bytesToRead = bytesToRead - length; } else { // Get out of the loop, if user is not connected anymore.. bytesToRead = -1; } } } catch (Exception ex) { Response.Write(ex.Message); // An error occurred.. } finally { if (stream != null) { stream.Close(); } } }
public void FirmarUserLoopButton_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos los documentos a firmar. Assembly assembly = Assembly.GetExecutingAssembly(); Stream fsPDF = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH); byte[] datos_a_firmarPDF = new byte[fsPDF.Length]; fsPDF.Read(datos_a_firmarPDF, 0, datos_a_firmarPDF.Length); Stream fsXML = assembly.GetManifestResourceStream(Global.DEMO_FILE_XML_PATH); byte[] datos_a_firmarXML = new byte[fsXML.Length]; fsXML.Read(datos_a_firmarXML, 0, datos_a_firmarXML.Length); Stream fsTXT = assembly.GetManifestResourceStream(Global.DEMO_FILE_TXT_PATH); byte[] datos_a_firmarTXT = new byte[fsTXT.Length]; fsTXT.Read(datos_a_firmarTXT, 0, datos_a_firmarTXT.Length); // En algunos casos, por ejemplo en el arranque de la aplicación puede ser interesante // Comprobar que efectivamente el servidor de firma está disponible System.Console.Write(clienteViafirma.ping("Prueba Conexión") + "\n"); // Registramos los documento que deseamos firmar en un listado. List <string> idsFirma = new List <string>(); // Este listado puede incluir varios tipos distintos de firma dentro del proceso. // Archivos sin firmar: string idTemporalPDF = clienteViafirma.PrepareFirmaWithTypeFileAndFormatSign("FicheroEjemploPDF.pdf", typeFile.PDF, typeFormatSign.PDF_PKCS7, datos_a_firmarPDF); string idTemporalXML = clienteViafirma.PrepareFirmaWithTypeFileAndFormatSign("FicheroEjemploXML.xml", typeFile.XML, typeFormatSign.XADES_EPES_ENVELOPED, datos_a_firmarXML); string idTemporalPDF2 = clienteViafirma.PrepareFirmaWithTypeFileAndFormatSign("FicheroEjemploPDF.pdf", typeFile.PDF, typeFormatSign.PDF_PKCS7, datos_a_firmarPDF); string idTemporalPDF3 = clienteViafirma.PrepareFirmaWithTypeFileAndFormatSign("FicheroEjemploPDF.pdf", typeFile.PDF, typeFormatSign.PDF_PKCS7, datos_a_firmarPDF); string idTemporalPDF4 = clienteViafirma.PrepareFirmaWithTypeFileAndFormatSign("FicheroEjemploPDF.pdf", typeFile.PDF, typeFormatSign.PDF_PKCS7, datos_a_firmarPDF); string idTemporalPDF5 = clienteViafirma.PrepareFirmaWithTypeFileAndFormatSign("FicheroEjemploPDF.pdf", typeFile.PDF, typeFormatSign.PDF_PKCS7, datos_a_firmarPDF); string idTemporalPDF6 = clienteViafirma.PrepareFirmaWithTypeFileAndFormatSign("FicheroEjemploPDF.pdf", typeFile.PDF, typeFormatSign.PDF_PKCS7, datos_a_firmarPDF); idsFirma.Add(idTemporalPDF); idsFirma.Add(idTemporalPDF2); idsFirma.Add(idTemporalPDF3); idsFirma.Add(idTemporalPDF4); idsFirma.Add(idTemporalPDF5); idsFirma.Add(idTemporalPDF6); idsFirma.Add(idTemporalXML); // Archivos de lote: string idLote = clienteViafirma.iniciarFirmaEnLotes(typeFormatSign.XADES_EPES_ENVELOPED); clienteViafirma.addDocumentoFirmaEnLote(idLote, "LoteEjemplo1.pdf", typeFile.PDF, datos_a_firmarPDF); clienteViafirma.addDocumentoFirmaEnLote(idLote, "LoteEjemplo2.xml", typeFile.XML, datos_a_firmarXML); clienteViafirma.addDocumentoFirmaEnLote(idLote, "LoteEjemplo3.txt", typeFile.TXT, datos_a_firmarTXT); idsFirma.Add(idLote); // Archivos ya firmados: // string idFirmado = clienteViafirma.signByServerWithTypeFileAndFormatSign("FicheroEjemploServer.pdf", datos_a_firmarPDF, aliasCert, passCert, typeFile.PDF, typeFormatSign.PDF_PKCS7); // idsFirma.Add(idFirmado); // Iniciamos el proceso de firma redireccionando al usuario a Viafirma.. // Esto redireccionará al usuario para la firma de los documentos // con una sola intervención del usuario. clienteViafirma.solicitarFirmasIndependientes(idsFirma.ToArray()); }
public void InitDigitalizedButton_Click(object sender, EventArgs e) { //Recuperamos la instancia del cliente ViafirmaClient clienteViafirma = ViafirmaClientFactory.GetInstance(); // Recuperamos el documento a firmar. Assembly assembly = Assembly.GetExecutingAssembly(); Stream fs = assembly.GetManifestResourceStream(Global.DEMO_FILE_PDF_PATH); byte[] datos_a_firmar = new byte[fs.Length]; fs.Read(datos_a_firmar, 0, datos_a_firmar.Length); //recuperamos la clave pública de encriptación Stream pemStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EjemploWebViafirmaClientDotNet.resources.xnoccio.pem"); String pem = new StreamReader(pemStream).ReadToEnd(); // En algunos casos, por ejemplo en el arranque de la aplicación, puede ser interesante comprobar conectividad System.Console.Write(clienteViafirma.ping("Prueba Conexión") + "\n"); //Creamos el objeto documento con los datos a firmar documento doc = new documento(); doc.nombre = "signatureDigitalized.pdf"; doc.datos = datos_a_firmar; doc.typeFormatSign = typeFormatSign.DIGITALIZED_SIGN; doc.tipo = typeFile.PDF; //Creamos la politica de firma policy pol = PolicyUtil.newPolicy(typeFormatSign.DIGITALIZED_SIGN, typeSign.ATTACHED); //Indica el color de fondo de la pantalla (para aquellos dispositivos de firma que lo permitan - dispositivos móviles) // PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_SIGN_BACK_COLOUR, "#0000FF"); //Indica el color de la firma de la pantalla (para aquellos dispositivos de firma que lo permitan - dispositivos móviles) PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_SIGN_COLOUR, "#FF0000"); //Indica el texto de ayuda que aparece en la pantalla PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_SIGN_HELP_TEXT, "Texto de ayuda aportado por el integrador"); //Logo a mostrar (para aquellos dispositivos de firma que lo permitan - dispositivos móviles ) // PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_SIGN_LOGO, logoStamp); //Rectangulo donde se fija la firma // PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_SIGN_RECTANGLE, new Rectangle(400,60,160,120)); //Biometric alias - pass son utilizados para firmar los datos biometricos en servidor (el alias debe existir en el servidor) PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_SIGN_BIOMETRIC_ALIAS, "xnoccio"); PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_SIGN_BIOMETRIC_PASS, "12345"); //Clave publica en formato pem con la que cifrar los datos biometricos, si no se indica no se cifran PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_SIGN_BIOMETRIC_CRYPTO_PEM, pem); //Pagina donde insertar la firma, -1 para la ultima pagina, si no se indica, en iOS/Android se permitirá seleccionar la pagina/s manualmente, en tabletas digitalizadoras se pondrá en la última página // PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_SIGN_PAGE, -1); //Firma en servidor del documento PDF (en este ejemplo se usa el mismo certificado que en la firma en servidor de los datos biométricos) PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_SIGN_ALIAS, "xnoccio"); PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_SIGN_PASS, "12345"); //Información adicional mapeada como título de firma (por ejemplo el nombre del firmante) PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_SIGNATURE_INFO, "Firmante de ejemplo"); //Estados permitidos para localización GPS (para aquellos dispositivos de firma que lo permitan - dispositivos móviles) // PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_LOCATION_STATUS, "0"); //Indica los stylus permitidos (para aquellos dispositivos de firma que lo permitan - dispositivos móviles) // PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_PRESSURE_STYLUS, ""); //Indica si se muestra o no valores de presión (para aquellos dispositivos de firma que lo permitan - dispositivos móviles) // PolicyUtil.AddParameter(pol, PolicyParams.DIGITALIZED_PRESSURE_INFO, ""); // Registramos el documento que deseamos firmar. Obteniendo un identificador temporal. // Este identificador temporal no es necesario que sea almacenado ya que sólo tiene validez durante el proceso de firma. string idTemporalFirma = clienteViafirma.PrepareSignWithPolicy(pol, doc); System.Console.Write("idTemporalFirma: " + idTemporalFirma); //Logica del ejemplo para descagar el fichero con la extension correcta Session["extension"] = ".pdf"; // Iniciamos el proceso de firma redireccionando al usuario a Viafirma.. // Esto redireccionará al usuario a Viafirma para la firma del documento con el // identificador de firma indicado. clienteViafirma.Sign(idTemporalFirma); }