파일 CRC 및 MD5 가져오기

1200 단어 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.


좋은 웹페이지 즐겨찾기