Download - Function Para Criptografar Em Md5

Transcript
Page 1: Function Para Criptografar Em Md5

Function para Criptografar em Md5

Obs : para que essa function possa funcioanar precisa ter :unit Wcrypt2.pas.http://stuff.irsoft.de/CryptoAPI2.zipnesse link acima tem Wicrypt2.pas para download

function TForm1.md5(const Input: String): String;var  hCryptProvider: HCRYPTPROV;  hHash: HCRYPTHASH;  bHash: array[0..$7f] of Byte;  dwHashLen: DWORD;  pbContent: PByte;  i: Integer;begin  dwHashLen := 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), 0) then      begin        if CryptGetHashParam(hHash, HP_HASHVAL, @bHash[0], @dwHashLen, 0) then        begin          for i := 0 to dwHashLen - 1 do          begin            Result := Result + Format('%.2x', [bHash[i]]);          end;        end;      end;      CryptDestroyHash(hHash);    end;    CryptReleaseContext(hCryptProvider, 0);  end;  Result := AnsiLowerCase(Result);

end;