获取文件CRC和MD5

  1. unit untCRCMD5;  
  2.   
  3. interface  
  4.   
  5. { 获取文件CRC校验码 }  
  6. function GetFileCRC(const iFileName: string): String;  
  7. { 获取字符串CRC校验码 }  
  8. function GetStringCRC(const Str: string): Cardinal;  
  9. { 取文件MD5码 }  
  10. function GetFileMD5(const iFileName: string): String;  
  11.   
  12. implementation  
  13.   
  14. uses Classes, IdHashMessageDigest, IdHashCRC;  
  15.   
  16. { 获取文件CRC校验码 }  
  17. function GetFileCRC(const iFileName: string): String;  
  18. var  
  19.   MemSteam: TMemoryStream;  
  20.   MyCRC   : TIdHashCRC32;  
  21. begin  
  22.   MemSteam := TMemoryStream.Create;  
  23.   MemSteam.LoadFromFile(iFileName);  
  24.   MyCRC  := TIdHashCRC32.Create;  
  25.   Result := MyCRC.HashStreamAsHex(MemSteam);  
  26.   MyCRC.Free;  
  27.   MemSteam.Free;  
  28. end;  
  29.   
  30. { 获取字符串CRC校验码 }  
  31. function GetStringCRC(const Str: string): Cardinal;  
  32. var  
  33.   MyCRC: TIdHashCRC32;  
  34. begin  
  35.   MyCRC  := TIdHashCRC32.Create;  
  36.   Result := MyCRC.HashValue(Str);  
  37.   MyCRC.Free;  
  38. end;  
  39.   
  40. { 取文件MD5码 }  
  41. function GetFileMD5(const iFileName: string): String;  
  42. var  
  43.   MemSteam: TMemoryStream;  
  44.   MyMD5   : TIdHashMessageDigest5;  
  45. begin  
  46.   MemSteam := TMemoryStream.Create;  
  47.   MemSteam.LoadFromFile(iFileName);  
  48.   MyMD5  := TIdHashMessageDigest5.Create;  
  49.   Result := MyMD5.HashStreamAsHex(MemSteam);  
  50.   MyMD5.Free;  
  51.   MemSteam.Free;  
  52. end;  
  53.   
  54. end.  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值