PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → HashString
HashString
Iniciado por guest, 14,sep. 2017 20:11 - 4 respuestas
Publicado el 14,septiembre 2017 - 20:11
I have a string, 's_ToHash', populated with 3 values which when concatenated produce the string 123456789AAA3321-12BH-A2200001

I need to create an MD5 hash of that and I require the value of 507c9d79c192da6e86428919ee0382dc to be returned

WinDev returns, depending on which HashString algorithm I use either

HashString(HA_MD5_128,s_ToHash) returns 'P|yÁ’Ún†B‰<25>î<3>‚Ü'
or
HashString(HA_HMAC_MD5_128,s_ToHash) returns ')v_dÂIÊY49ñœi2éá'

The returned value is the same regardless of whether I use a Buffer or String to receive the result

I tried inputing my string into a number of online MD5 generators and all returned the ASCII result I require.

Anyone have any idea how I can convert,progamatically, the WD result into the one I need, i.e ASCII text.
Publicado el 14,septiembre 2017 - 20:21
It looks like you need you result in hexadecimal, if so try using BufferToHexa
or break your string byte to byte and using asc (or val i don't remember what is the right one) and numtostring you can get the hex of that byte.
Publicado el 14,septiembre 2017 - 21:06
Hi Derek,

you need to add a
MyResult is strin=replace(replace(BufferToHexa(MyBuffer)," ",""),CR,"")

Best regards
Publicado el 14,septiembre 2017 - 21:07
Thanks Paulo, set me on the right course

Using BufferToHexa() returned '50 7C 9D 79 C1 92 DA 6E 86 42 89 19 EE 03 82 DC' which is actually the string I was looking for.
Just needed to reformat it.
//Create hash validation string bufHash = HashString(HA_MD5_128,StringBuild("%1%2%3",s_AccNum,s_AccAPI,s_SubNum)) s_bufHEX = BufferToHexa(bufHash) //Convert Hash result to HEX s_HEXTxt = s_bufHEX //Save HEX as a text string s_MD5 = Lower(NoSpace(s_HEXTxt,sscAll)) //Format text
s_MD5 now = '507c9d79c192da6e86428919ee0382dc'

Spot on, thanks again
Publicado el 14,septiembre 2017 - 21:14
Hi Fabrice

Much more economical withe coding - Just needed to add the Lower() command

MyResult is string=Lower(Replace(Replace(BufferToHexa(bufHash)," ",""),CR,""))

Works a treat, thanks