RSS订阅 | 匿名投稿
您的位置:网站首页 > 加密 > 正文

delphi 读取文件的MD5值

作者:admin 来源: 日期:2011/8/17 10:31:24 人气: 标签:

 
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 www.delphitop.com}
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.

读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址: