读取文件的MD5值

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,IdHashMessageDigest,IdGlobal, IdHash;

type
TForm1
= class(TForm)
btn1: TButton;
OpenSwf1: TOpenDialog;
edt1: TEdit;
procedure btn1Click(Sender: TObject);
private
function StreamToMD5(S: TFileStream): String;
{ Private declarations }
public
{ Public declarations }
end;

type
TMD5
= class(TIdHashMessageDigest5);

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
var
filesen:TFileStream;
begin
if OpenSwf1.Execute then
begin
filesen:
=TFileStream.Create(OpenSwf1.FileName,fmOpenRead or fmShareExclusive);
edt1.Text:
=StreamToMD5(filesen);
filesen.Free;
end;
end;

//读文件MD5值
function TForm1.StreamToMD5(S: TFileStream): String;
var
Md5Encode: TMD5;
begin
Md5Encode:
= TMD5.Create;
try
Result :
=Md5Encode.HashStreamAsHex(s) ;
finally
Md5Encode.Free;
end;
end;

end.

  

posted @ 2011-08-09 10:10  许明吉博客  阅读(1160)  评论(0编辑  收藏  举报