Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 25-11-2014
elmago00 elmago00 is offline
Miembro
NULL
 
Registrado: ago 2013
Posts: 86
Poder: 11
elmago00 Va por buen camino
Ayuda a pasar codigo delphi7 a XE3

Hola,
llevo semanas tratando de hacer funcionar bien un código de delphi7 en embarcadero xe3.
pero da la casualidad, que en delphi7 me da un código PIC y en embarcadero me genera otro

Código Delphi [-]
function md5(const Input: String): String;
var
  hCryptProvider: HCRYPTPROV;
  hHash: HCRYPTHASH;
  bHash: array[0..$7f] of Byte;
  dwHashBytes: Cardinal;
  pbContent: PByte;
  i: Integer;

begin
  dwHashBytes := 16;
  pbContent := Pointer(PChar(Input));

  Result := '';

  if CryptAcquireContext(@hCryptProvider, nil, nil, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT or CRYPT_MACHINE_KEYSET) then
  begin
    if CryptCreateHash(hCryptProvider, CALG_MD5, 0, 0, @hHash) then
    begin
      if CryptHashData(hHash, pbContent, Length(Input) * sizeof(Char), 0) then
      begin
        if CryptGetHashParam(hHash, HP_HASHVAL, @bHash[0], @dwHashBytes, 0) then
        begin
          for i := 0 to dwHashBytes - 1 do
          begin
            Result := Result + Format('%.2x', [bHash[i]]);
          end;
        end;
      end;
      CryptDestroyHash(hHash);
    end;

    CryptReleaseContext(hCryptProvider, 0);
  end;

  Result := AnsiLowerCase(Result);

  end;


procedure TForm2.Button1Click(Sender: TObject);
var
aHash,S,  aKey : String;
Tmp : array [1..16] of integer;
i:integer;
  begin



aHash := Md5(Edit1.text);



for i:=1 to 16 do Tmp[i]:=StrToInt('$'+rightStr(leftstr(aHash,2*i),2));



aKey:='';
for i:=1 to 8 do aKey:=  aKey + IntToStr((((Tmp[i]+Tmp[i+8])and$FF)*9)div$FF);


while(length(akey)<8) do aKey:='0'+aKey;
memo1.lines.Clear;

Memo1.Lines.Add('PIC:' + akey);

end;

end.

valor : 235641110256249
resultado PIC:47553704 esto en XE3 pero en delphi7 da : PIC:86536540


uso esto
Wcrypt2.rar


gracias por la ayuda
Responder Con Cita
  #2  
Antiguo 25-11-2014
Avatar de ElKurgan
[ElKurgan] ElKurgan is offline
Miembro Premium
 
Registrado: nov 2005
Posts: 1.232
Poder: 20
ElKurgan Va camino a la fama
Todo tiene que ver con que a partir de Delphi 2009 los String y los Char se corresponden con caracteres Unicode, mientras que los antiguos String y Char son ahora AnsiString y AnsiChar.

Prueba con este código, a ver:

Código Delphi [-]
//function md5(const Input: String): String;
function md5(const Input: AnsiString): AnsiString;
var
  hCryptProvider: HCRYPTPROV;
  hHash: HCRYPTHASH;
  bHash: array[0..$7f] of Byte;
  dwHashBytes: Cardinal;
  pbContent: PByte;
  i: Integer;

begin
  dwHashBytes := 16;
//  pbContent := Pointer(PChar(Input));
  pbContent := Pointer(PAnsiChar(Input));

  Result := '';

  if CryptAcquireContext(@hCryptProvider, nil, nil, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT or CRYPT_MACHINE_KEYSET) then
  begin
    if CryptCreateHash(hCryptProvider, CALG_MD5, 0, 0, @hHash) then
    begin
//      if CryptHashData(hHash, pbContent, Length(Input) * sizeof(Char), 0) then
      if CryptHashData(hHash, pbContent, Length(Input) * sizeof(AnsiChar), 0) then
      begin
        if CryptGetHashParam(hHash, HP_HASHVAL, @bHash[0], @dwHashBytes, 0) then
        begin
          for i := 0 to dwHashBytes - 1 do
          begin
            Result := Result + Format('%.2x', [bHash[i]]);
          end;
        end;
      end;
      CryptDestroyHash(hHash);
    end;

    CryptReleaseContext(hCryptProvider, 0);
  end;

  Result := AnsiLowerCase(Result);

  end;

Veras que sólo he sustituido los "Char" por "AnsiChar", y la llamada a la función con AnsiString

Saludos
Responder Con Cita
  #3  
Antiguo 25-11-2014
elmago00 elmago00 is offline
Miembro
NULL
 
Registrado: ago 2013
Posts: 86
Poder: 11
elmago00 Va por buen camino
gracias [ElKurgan] solucionaste el problema
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

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
Ayuda a pasar este código a firemonkey. elmago00 FireMonkey 55 08-01-2015 16:25:18
pasar for (Entry in FSMBiosTablesList) do a delphi7 fcios Varios 2 01-05-2013 19:50:19
Ayuda a Pasar Codigo Delphi a C++ yelian C++ Builder 9 26-11-2009 21:32:26
Pasar de Turbo Pascal 7 a DELPHI7 BEPAI Varios 6 14-03-2007 12:44:19
Problemas RBuilder al pasar de delphi5 a delphi7 neon Impresión 0 26-08-2004 15:38:35


La franja horaria es GMT +2. Ahora son las 19:14:13.


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