delphi 获取文件CRC和MD5


本文整理自网络,侵删。

 

unit untCRCMD5;

interface

{ 获取文件CRC校验码 }
function GetFileCRC(const iFileName: string): String;
{ 获取字符串CRC校验码 }
function GetStringCRC(const Str: string): Cardinal;
{ 取文件MD5码 }
function GetFileMD5(const iFileName: string): String;

implementation

uses Classes, IdHashMessageDigest, IdHashCRC;

{ 获取文件CRC校验码 }
function GetFileCRC(const iFileName: string): String;
var
  MemSteam: TMemoryStream;
  MyCRC   : TIdHashCRC32;
begin
  MemSteam := TMemoryStream.Create;
  MemSteam.LoadFromFile(iFileName);
  MyCRC  := TIdHashCRC32.Create;
  Result := MyCRC.HashStreamAsHex(MemSteam);
  MyCRC.Free;
  MemSteam.Free;
end;

{ 获取字符串CRC校验码 }
function GetStringCRC(const Str: string): Cardinal;
var
  MyCRC: TIdHashCRC32;
begin
  MyCRC  := TIdHashCRC32.Create;
  Result := MyCRC.HashValue(Str);
  MyCRC.Free;
end;

{ 取文件MD5码 }
function GetFileMD5(const iFileName: string): String;
var
  MemSteam: TMemoryStream;
  MyMD5   : TIdHashMessageDigest5;
begin
  MemSteam := TMemoryStream.Create;
  MemSteam.LoadFromFile(iFileName);
  MyMD5  := TIdHashMessageDigest5.Create;
  Result := MyMD5.HashStreamAsHex(MemSteam);
  MyMD5.Free;
  MemSteam.Free;
end;

end.

相关阅读 >>

Delphi �c 如何将多个文件扩展名传递给tdirectory.getfiles?

Delphi 去掉文件只读属性

Delphi is 与 as 运算符举例

Delphi webbrowser 查找对话框

Delphi console 清屏代码

Delphi memo1 光标跟随鼠标移动

Delphi 检查父进程

Delphi 调用批处理

Delphi twebbrowser出现 method pastehtml not supported by automation object 解决方法

Delphi 检查父进程

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...