Skip to content

Instantly share code, notes, and snippets.

@dkstar88
Created August 1, 2013 08:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkstar88/6129702 to your computer and use it in GitHub Desktop.
Save dkstar88/6129702 to your computer and use it in GitHub Desktop.
Short hash function name wrapper for TIdHashMessageDigest5
unit hashutil;
interface
uses SysUtils, Classes, IdGlobal, IdHash, IdHashMessageDigest, IdHashSHA, IdHashCRC;
function MD5(S: String): String; overload;
function MD5(S: TStream): String; overload;
function MD5_Bytes(S: String): TIdBytes;
function MD5_File(AFilename: String): String;
implementation
function MD5_File(AFilename: String): String;
var
fs: TFileStream;
begin
with TIdHashMessageDigest5.Create do
begin
fs := TFileStream.Create(AFilename, fmOpenRead);
try
Result := HashStreamAsHex(fs);
finally
fs.Free;
end;
Free;
end;
end;
function MD5_Bytes(S: String): TIdBytes;
begin
with TIdHashMessageDigest5.Create do
begin
Result := HashString(S);
Free;
end;
end;
function MD5(S: String): String;
begin
with TIdHashMessageDigest5.Create do
begin
Result := HashStringAsHex(S);
Free;
end;
end;
function MD5(S: TStream): String;
begin
with TIdHashMessageDigest5.Create do
begin
Result := HashStreamAsHex(S);
Free;
end;
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment