Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 26-05-2021
jars jars is offline
Miembro
 
Registrado: mar 2004
Posts: 279
Poder: 21
jars Va por buen camino
Encriptar con certificado

Hola.
Me pasaron este código en .Net para encriptar y firmar con certificado para una aplicación en Delphi 7 pero no entiendo como poder hacerlo.
Si alguien tiene experiencia en esto de claves publica y privada me podría dar una mano?.
Gracias.

Código:
La función EncriptarConCertificado de la DLL hace lo siguiente:

X509Certificate2 certificado = new X509Certificate2(pathCertificado);
RSACryptoServiceProvider RSAalgPBL = (RSACryptoServiceProvider)certificado.PublicKey.Key;
RSAParameters Key = RSAalgPBL.ExportParameters(false);
ProcesarStringAEncriptar(StringAEncriptar, Key);

 private string ProcesarStringAEncriptar(string StringAEncriptar, RSAParameters Key)
{
            RSACryptoServiceProvider RSAalg = null;
            SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider();
            string strEncriptado = "";
            try
            {
                // Create a new instance of RSACryptoServiceProvider using the key from RSAParameters. 
                RSAalg = new RSACryptoServiceProvider(1280);
                //Importo la clave
                RSAalg.ImportParameters(Key);
                //Encripto
                strEncriptado = Convert.ToBase64String(RSAalg.Encrypt(ASCIIEncoding.ASCII.GetBytes(StringAEncriptar), true));
                return strEncriptado;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                RSAalg.Dispose();
                SHA1.Dispose();
            }
}

La función FirmarStringConCertificado de la DLL hace lo siguiente:

X509Certificate2 certificado = new X509Certificate2(pathCertificado, passCertificado, X509KeyStorageFlags.Exportable);
RSACryptoServiceProvider RSAalgPV = (RSACryptoServiceProvider)certificado.PrivateKey;
RSAParameters Key = RSAalgPV.ExportParameters(true);
Convert.ToBase64String(this.ProcesarStringAFirmar(STR_To_Sign, Key));

private byte[] ProcesarStringAFirmar(string StringAFirmar, RSAParameters Key)
{
            try
            {
                //Leo el archivo
                return this.HashAndSign(ASCIIEncoding.ASCII.GetBytes(StringAFirmar), Key);
            }
            catch (Exception)
            {
                throw;
            }
}
Responder Con Cita
  #2  
Antiguo 27-05-2021
Punzo Punzo is offline
Miembro
 
Registrado: abr 2006
Posts: 96
Poder: 19
Punzo Va por buen camino
Dale una leída a este link, a ver si te puede ayudar
https://github.com/bambucode/tfacturaelectronica
Responder Con Cita
  #3  
Antiguo 31-05-2021
jars jars is offline
Miembro
 
Registrado: mar 2004
Posts: 279
Poder: 21
jars Va por buen camino
Gracias Punzo, lo voy a checkear
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Certificado de Seguridad Alexander Varios 0 24-02-2005 19:19:34
Certificado en DELPHI fjolivares Varios 1 22-02-2005 18:13:10


La franja horaria es GMT +2. Ahora son las 22:33:24.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi