开发者

How to do a md5 hash of some hex values?

开发者_开发问答I'm a newbie in php. what i need to do is to do md5 hashing on some hex values. For example, I want to do an md5 hash of 0x14. the actual hash of that, is:

15f41a2e96bae341dde485bb0e78f485

but i can not reproduce that in PHP.

md5 (0x14);

Doesn't work, even

md5(chr(hexdec(14)));

doesn't work. cause its not an actual character

I tried every possibility that i could think of, searched countless hours on the Internet, still nothing. How can i make this work?


php> echo md5(chr(0x14))
15f41a2e96bae341dde485bb0e78f485


This works for me

md5(chr(0x14)); //15f41a2e96bae341dde485bb0e78f485


You can write binary values into any double quoted string with the hexadecimal escape sequence, maybe this helps (Demo):

md5("\x14"); # 15f41a2e96bae341dde485bb0e78f485


hexdec takes a string, so your example would work if you quote the '14'

md5(chr(hexdec('14')));

alternatively, you could use a hexadecimal numeric literal

md5(chr(0x14));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜