Delphi 文件CRC和MD5校验


本文整理自网络,侵删。

 
CRC和MD5用于文件和数据的传输校验,以确认是否接收成功。


unit CRCMD5;
 
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.

来源:https://www.cnblogs.com/hnxxcxg/p/11079660.html

相关阅读 >>

Delphi xe5 android 使用system.zip单元释放资源文件

Delphi fmx 获取控件句柄

Delphi 与 c/c++ 数据类型对照表

Delphi 与 xml 示例(直接利用ixmldocument)

Delphi 获取计算机名和用户名

Delphi winapi: getwindowrect、getclientrect - 获取窗口的外部与内部矩形

Delphi整理一(基础知识)

Delphi 文件/流的加密解密方法

Delphi 时间与字符串

Delphi使用ado读写excel文件

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



打赏

取消

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

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

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

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

评论

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