12
How to get the MD5 of a file in Delphi?
12
How to get the MD5 of a file in Delphi?
9
The code below uses Indy, which accompanies Delphi.
uses
IdHashMessageDigest, IdHash;
function MD5DoArquivo(const FileName: string): string;
var
IdMD5: TIdHashMessageDigest5;
FS: TFileStream;
begin
IdMD5 := nil;
FS := nil;
try
IdMD5 := TIdHashMessageDigest5.Create;
FS := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
Result := IdMD5.HashStreamAsHex(FS)
finally
FS.Free;
IdMD5.Free;
end;
end;
4
In the older versions of Delphi(as a 7), the component Indy is not built in by default. If you want to do this without using components, you can use esse código redistributed by software developers CACIC.
For example, to calculate the MD5 of a string, use:
Uses md5;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
ShowMessage(MD5Print(MD5String('FoooBarrr')));
end;
To calculate the MD5 of a file, is used:
Uses md5;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
ShowMessage(MD5Print(MD5File('Arquivo.exe')));
end;
:-)
Browser other questions tagged delphi md5
You are not signed in. Login or sign up in order to post.
+1 for using a virtually native component.
– adamasan