Browse Source

* simple strtomd5 function from mantis #23397

git-svn-id: trunk@26350 -
marco 11 years ago
parent
commit
2a4385c196
1 changed files with 20 additions and 0 deletions
  1. 20 0
      packages/hash/src/md5.pp

+ 20 - 0
packages/hash/src/md5.pp

@@ -147,10 +147,13 @@ function MD4Print(const Digest: TMD4Digest): String; inline;
 function MD4Match(const Digest1, Digest2: TMD4Digest): Boolean; inline;
 
 function MD5Print(const Digest: TMD5Digest): String; inline;
+function StrtoMD5(const MD5String:String):TMDDigest;
 function MD5Match(const Digest1, Digest2: TMD5Digest): Boolean; inline;
 
 implementation
 
+uses sysutils;
+
 // inverts the bytes of (Count div 4) cardinals from source to target.
 procedure Invert(Source, Dest: Pointer; Count: PtrUInt);
 var
@@ -664,4 +667,21 @@ begin
   Result := MDMatch(Digest1, Digest2);
 end;
 
+//convert the String representation of a digest to a TMDDigest
+//on error all fields are set to $00
+function StrtoMD5(const MD5String:String):TMDDigest;
+   var I: Byte;
+       t: integer;
+       f: boolean;
+   begin
+     f:= Length(MD5String) = 32;
+     if f then
+      for I := 0 to 15 do
+       begin
+        f:= f and TryStrToInt('$'+copy(MD5String,i*2+1, 2), t);
+        Result[I]:= t;
+       end;
+     if not f then
+       FillChar(Result, Sizeof(Result), 0);
+   end; 
 end.