主页 > 编程资料 > Delphi >
发布时间:2015-09-22 作者:网络 阅读:125次

 
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.

关键字词: