A function similar to this one, is what I'd love to see. PHP5 has it for MD5 and SHA too I believe.
The other benefit is that binary should be much faster right? (or does the md5 implementation actually do it as hex internally?)
Code: Select all
EnableExplicit
Procedure.l MD5FingerprintBin(*buf,len.i,*md5bin) ;returns a pointer to a 16 byte md5 binary fingerprint
Protected hex.s, x.i, a.i, b.i, c.i, i.i
hex.s=UCase(MD5Fingerprint(*buf,len))
i=0
For x=0 To 31 Step 2
a=PeekB((@hex)+x) & $FF
If a<58
a=a-48
Else
a=a-55
EndIf
b=PeekB((@hex)+(x+1)) & $FF
If b<58
b=b-48
Else
b=b-55
EndIf
PokeB(*md5bin+i,(a<<4)+b)
i+1
Next
ProcedureReturn *md5bin
EndProcedure
Define *md5bin,text$
*md5bin=AllocateMemory(16)
text$="Test!"
MD5FingerprintBin(@text$,StringByteLength(text$),*md5bin) ;returns a pointer to *md5bin or 0 if error.