unit uMD5;

interface

uses IdHashMessageDigest, Classes, SysUtils;

function MD5String(const Value: string): string;
function MD5Arquivo(const Value: string): string;

implementation

{Função : MD5String(Const Value : String): String;}

function MD5String(const Value: string): string;
var
  xMD5: TIdHashMessageDigest5;
begin
  xMD5 := TIdHashMessageDigest5.Create;
  try
    Result := LowerCase(xMD5.HashStringAsHex(Value));
  finally
    xMD5.Free;
  end;
end;

function MD5Arquivo(const Value: string): string;
var
  xMD5: TIdHashMessageDigest5;
  xArquivo: TFileStream;
begin
  xMD5 := TIdHashMessageDigest5.Create;
  xArquivo := TFileStream.Create(Value, fmOpenRead OR fmShareDenyWrite);
  try
    Result := xMD5.HashStreamAsHex(xArquivo);
  finally
    xArquivo.Free;
    xMD5.Free;
  end;
end;

end.
