Created
August 1, 2013 08:56
-
-
Save dkstar88/6129698 to your computer and use it in GitHub Desktop.
Short hash function name wrapper for TIdHashMessageDigest5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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