Question

I understand not wanting to use '\0', but all the rest in the extended ASCII range is usable right?

Wouldn't this provide a much better/secure/"less coliding" hash?

Was it helpful?

Solution

You're starting from false premise -- they produce a result that can (does) include all 8-bit values from 0 to 255. Just for example, one of the test vectors for SHA-256 is an input of "abc". The result from this (in hexadecimal) is:

ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad

Just within that test, the result includes bytes with values from 0x03 to 0xff.

For display, that may be (often is) rendered in something like hexadecimal. For transmission in email they're often encoded with something like MIME or UUENCODE. The hash itself, however, is not limited in this way.

Transforming the result this way makes no difference to collision resistance -- you still have 160/256/whatever bits of actual data, but the representation is expanded.

OTHER TIPS

The result is just hexadecimal encoded to be better readable.

In fact, those hash algorithms are outputting numbers, not strings. They use only letters a-f in combination with numbers 0-9, which makes the output a hexadecimal number.

MD5 produces an 128 bit hash. (16 byte) sha, depending of whether is sha1 or sha256 produces either 160 bit (20 byte) or 256 bit (32 byte) hash. Note that I'm talking about binary length/strength. The longer the less likely a collision occurs.

The fact that most users stick it into a DB field or whatnot makes it convenient to convert it to ASCII using varions binary-ascii conversion algos. This should not influence the strength of collision probability at all since you'll end up with a larger ASCII string.

FWIW I've been using SHA1, SHA256 in crypto products in binary form for over 5 years and I'd recommend choosing hashes in this following order, from the strongest to the weakest: SHA256, SHA1, MD5. There is a website that can "reverse" MD5 so I'd strongly suggest against it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top