Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Go Back   Foros Club Delphi > Principal > Varios
Register FAQ Members List Calendar Guía de estilo Today's Posts

Coloboración Paypal con ClubDelphi

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 26/05/2021
jars jars is offline
Miembro
 
Join Date: Mar 2004
Posts: 283
Poder: 23
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.

Code:
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;
            }
}
Reply With Quote
  #2  
Old 27/05/2021
Punzo Punzo is offline
Miembro
 
Join Date: Apr 2006
Posts: 98
Poder: 21
Punzo Va por buen camino
Dale una leída a este link, a ver si te puede ayudar
https://github.com/bambucode/tfacturaelectronica
Reply With Quote
  #3  
Old 31/05/2021
jars jars is offline
Miembro
 
Join Date: Mar 2004
Posts: 283
Poder: 23
jars Va por buen camino
Gracias Punzo, lo voy a checkear
Reply With Quote
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Certificado de Seguridad Alexander Varios 0 24/02/2005 19:19
Certificado en DELPHI fjolivares Varios 1 22/02/2005 18:13


All times are GMT +2. The time now is 08:51.


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