码迷,mamicode.com
首页 > 其他好文 > 详细

获取文件CRC和MD5

时间:2014-11-06 16:40:13      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   文件   div   on   log   cti   ad   

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.

  

获取文件CRC和MD5

标签:blog   io   ar   文件   div   on   log   cti   ad   

原文地址:http://www.cnblogs.com/delphi7456/p/4078880.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!