打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
delphi开发获取文件MD5值的小demo

unit Umain;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    Memo1: TMemo;
    procedure Button1Click(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.Button1Click(Sender: TObject);
var
    filesen:TFileStream;
    str:string;
begin
    if opendialog1.Execute then
    begin
        filesen:=TFileStream.Create(opendialog1.FileName,fmopenread or fmshareExclusive);
        str:=StreamToMD5(filesen);
        memo1.Lines.Add(str);
        filesen.Free;
    end;
end;

function TForm1.StreamToMD5(s:TFileStream):string;
var
    MD5Encode:TMD5;
    long:T4x4LongWordRecord;
begin
    MD5Encode:=TMD5.Create;
    try
        long:=md5encode.HashValue(s);
        result:=MD5Encode.AsHex(long);
    finally
        MD5Encode.Free;
    end;
end;

end.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
《Mastering Delphi 6》学习笔记之十
要谨慎使用Indy的TIdHashMessageDigest类
Delphi 中的MD5实现方法及delphi2009和delphi2010中用法
Delphi文件操作
Delphi 利用 CreateProcess 读取 CMD 程序的显示信息和返回结果
Excel文件导入StringGrid
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服