Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Bases de datos > Firebird e Interbase
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #10  
Antiguo 07-09-2017
Avatar de Casimiro Noteví
Casimiro Noteví Casimiro Noteví is offline
Merodeador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.679
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví Tiene un aura espectacular
Otro ejemplito:

Código Delphi [-]
// Estas dos "units" las puedes encontrar en el adjunto que he puesto
uses AES, Base64;
 
function Cifrar(Str,Clave: String): String;
var
  Src: TStringStream;
  Dst: TMemoryStream;
  Size: Integer;
  Key: TAESKey;
  ExpandedKey: TAESExpandedKey;
begin
  Result:= EmptyStr;
  Src:= TStringStream.Create(Str);
  try
    Dst:= TMemoryStream.Create;
    try
      // Preparamos la clave, lo ideal es que tenga 32 caracteres
      FillChar(Key,Sizeof(Key),#0);
      if Length(Clave) > Sizeof(Key) then
        move(PChar(Clave)^,Key,Sizeof(key))
      else
        move(PChar(Clave)^,Key,Length(Clave));
      AEsExpandKey(ExpandedKey,Key);
      // Guardamos el tamaño del texto original
      Size:= Src.Size;
      Dst.WriteBuffer(Size,Sizeof(Size));
      // Ciframos el texto
      AESEncryptStreamECB(Src,Dst,ExpandedKey);
      // Lo codificamos a base64
      Result:= BinToStr(Dst.Memory,Dst.Size);
    finally
      Dst.Free;
    end;
  finally
    Src.Free;
  end;
end;



function Descifrar(Str,Clave: String): String;
var
  Src: TMemoryStream;
  Dst: TStringStream;
  Size: Integer;
  Key: TAESKey;
  ExpandedKey: TAESExpandedKey;
begin
  Result:= EmptyStr;
  Src:= TMemoryStream.Create;
  try
    Dst:= TStringStream.Create(Str);
    try
      StrToStream(Str,Src);
      Src.Position:= 0;
      FillChar(Key,Sizeof(Key),#0);
      if Length(Clave) > Sizeof(Key) then
        move(PChar(Clave)^,Key,Sizeof(key))
      else
        move(PChar(Clave)^,Key,Length(Clave));
      AESExpandKey(ExpandedKey,Key);
      // Leemos el tamaño del texto
      Src.ReadBuffer(Size,Sizeof(Size));
      AESDecryptStreamECB(Src,Dst,ExpandedKey);
      Dst.Size:= Size;
      Result:= Dst.DataString;
    finally
      Dst.Free;
    end;
  finally
    Src.Free;
  end;
end;

Para terminar, un pequeño ejemplo de cómo funciona:

* Ciframos el texto "Hola mundo": Str := Cifrar("Hola mundo",'1234567890');
* Ahora la variable Str contiene el texto: CgAAADpn2TqC3VGqJmIQdPzgAaA=
* Desciframos el texto anterior: Str := Descifrar("CgAAADpn2TqC3VGqJmIQdPzgAaA=",'1234567890');
* Ahora la variable Str vuelve a contener el texto: "Hola mundo"

--------------------------------------------------
Otro más: http://delphi.jmrds.com/node/96


Como ves, el amigo Seoane tiene bastantes recursos sobre el tema.
Archivos Adjuntos
Tipo de Archivo: zip cript.zip (11,3 KB, 23 visitas)
Responder Con Cita
 



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
Tablas Hash godel Lazarus, FreePascal, Kylix, etc. 3 19-02-2008 11:40:03
codigo hash maco2007 Varios 4 20-10-2007 17:01:04
Calcular hash md5 Lepe Trucos 1 10-05-2007 15:11:58
Hash RaulChemical Varios 1 07-09-2004 20:10:11
¿Hash or not Hash? hgiacobone Varios 5 17-07-2003 19:43:26


La franja horaria es GMT +2. Ahora son las 03:19:29.


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