type
pTMD5_CTX = ^TMD5_CTX;
TMD5_CTX = record
num:Array[0…1] of ULONG;
buf:Array[0…3] of ULONG;
input:Array[0…64-1] of Byte;
digest:Array[0…16-1] of Byte;
end;
TMD5Init = procedure(Ctx:Pointer);stdcall;
TMD5Update = procedure(Ctx:Pointer; lpBuf:Pointer; nLen:Integer);stdcall;
TMD5Final = procedure(Ctx:Pointer);stdcall;
var
g_IsMd5Load:Boolean;
g_MD5Init:TMD5Init = nil;
g_MD5Update:TMD5Update = nil;
g_MD5Final:TMD5Final = nil;
procedure LodMd5;
var
hMod:Cardinal;
begin
if not g_IsMd5Load then begin
hMod:=LoadLibrary(‘advapi32.dll’);
if hMod<>0 then begin
g_MD5Init:=GetProcAddress(hMod,‘MD5Init’);
g_MD5Update:=GetProcAddress(hMod,‘MD5Update’);
g_MD5Final:=GetProcAddress(hMod,‘MD5Final’);
if (@g_MD5Init<>nil) and (@g_MD5Update<>nil) and (@g_MD5Final<>nil) then begin
g_IsMd5Load:=True;
end;
end;
end;
end;
function WinMd5(str:AnsiString):AnsiString;
var
ctx:TMD5_CTX;
i:Integer;
begin
LodMd5;
Result:=‘’;
if g_IsMd5Load then begin
ZeroMemory(@ctx,sizeof(TMD5_CTX));
g_MD5Init(@ctx);
g_MD5Update(@ctx, @str[1], Length(str));
g_MD5Final(@ctx);
for i:=0 to 15 do begin
Result:=Result+lowercase(Format(‘%.2x’,[ctx.digest[i]]));
end;
end;
end;
{{{046CF2538FC6025489C9E10E4A8DEA6393F113789B90ACC90AB9778FCE0256A232953C9FEA2A61A3E2246EFA1B494EF6418F33A92AB82D63F059F51DDE7CC50D0D7091F61F65A73C933D92F21F080901429A3A}}}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)