2009年5月29日

Delphi 使用 Indy 取得檔案 md5sum


uses
IdHashMessageDigest, IdHash;

function md5sum(FileName: string): string;
var
MyMD5: TIdHashMessageDigest5;
Digest: T4x4LongWordRecord;
Stream: TStream;
begin
if FileExists(FileName) then begin
MyMD5 := TIdHashMessageDigest5.Create;
Stream := TFileStream.Create(FileName, fmOpenRead);
try
Digest := MyMD5.HashValue(Stream);
Result := MyMD5.AsHex(Digest);
finally
Stream.Free;
MyMD5.Free;
end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ShowMessage(md5sum('c:\boot.ini')); // FileName
end;

沒有留言:

網誌存檔