Ver Mensaje Individual
  #2  
Antiguo 25-11-2014
Avatar de ElKurgan
[ElKurgan] ElKurgan is offline
Miembro Premium
 
Registrado: nov 2005
Posts: 1.234
Reputación: 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