본문 바로가기
Delphi, RadStudio

[개발/델파이] MD5 - delphi에서 간단히 다루기

by SB리치퍼슨 2012. 10. 29.



uses 

  IdHashMessageDigest, IdHash;


// 문자열 -> MD5

function MD5Str(const S: String): String;

var IdMD5: TIdHashMessageDigest5;

begin

  IdMD5:=TIdHashMessageDigest5.Create;

  try

    Result:=IdMD5.HashStringAsHex(S);

  finally

    FreeAndNil(IdMD5);

  end;

end;



// 파일 -> MD5

function MD5File(const FilePath: String): String;

var

  IdMD5: TIdHashMessageDigest5;

  fStream: TFileStream;

begin

  Result:='';

  if not FileExists(FilePath) then Exit;


  IdMD5:=TIdHashMessageDigest5.Create;

  fStream:=TFileStream.Create(FilePath, fmOpenRead or fmShareDenyWrite);

  try

    Result:=IdMD5.HashStreamAsHex(fStream);

  finally

    FreeAndNil(fStream);

    FreeAndNil(IdMD5);

  end;

end;

반응형

댓글