델파이에서 MD5 해시 사용하기
uses IdHashMessageDigest, idHash;
//returns MD5 has for a file
function MD5(const fileName : string) :string;
var
idmd5 : TIdHashMessageDigest5;
fs : TFileStream;
begin
idmd5 := TIdHashMessageDigest5.Create;
fs := TFileStream.Create(fileName, fmOpenRead OR fmShareDenyWrite) ;
try
result := idmd5.AsHex(idmd5.HashValue(fs)) ;
finally
fs.Free;
idmd5.Free;
end;
end;
//returns MD5 has for a file
function MD5(const fileName : string) :string;
var
idmd5 : TIdHashMessageDigest5;
fs : TFileStream;
begin
idmd5 := TIdHashMessageDigest5.Create;
fs := TFileStream.Create(fileName, fmOpenRead OR fmShareDenyWrite) ;
try
result := idmd5.AsHex(idmd5.HashValue(fs)) ;
finally
fs.Free;
idmd5.Free;
end;
end;
2007 버전 이상에서는, 함수가 변경되어서, 다음과 같이
//returns MD5 has for a file
function MD5(const fileName : string) :string;
var
idmd5 : TIdHashMessageDigest5;
fs : TFileStream;
begin
idmd5 := TIdHashMessageDigest5.Create;
fs := TFileStream.Create(fileName, fmOpenRead OR fmShareDenyWrite) ;
try
result := idmd5.HashStreamAsHex(fs);
finally
fs.Free;
idmd5.Free;
end;
end;
function MD5(const fileName : string) :string;
var
idmd5 : TIdHashMessageDigest5;
fs : TFileStream;
begin
idmd5 := TIdHashMessageDigest5.Create;
fs := TFileStream.Create(fileName, fmOpenRead OR fmShareDenyWrite) ;
try
result := idmd5.HashStreamAsHex(fs);
finally
fs.Free;
idmd5.Free;
end;
end;
로 쓰면 됩니다.
댓글 없음:
댓글 쓰기