简体   繁体   中英

PHP crypt() - Returned md5 hash

The docs ( http://php.net/manual/de/function.crypt.php ) for the crypt() function show the following example for an MD5 hash:

$1$rasmusle$rISCgZzpwk3UhDidwXvin0

I understand, that "$1$" is the prefix, which contains the information, that the hash is an MD5 hash.

But how is the rest of the string an MD5 hash? Normally it should be a 32 char string (0-9, af), right?

I'm sure, it's a stupid question, but I still want to ask.

Normally it should be a 32 char string (0-9, af), right?

That is not correct (at least strictly speaking). Technically, a MD5 hash is a 128 bit numeric value . The form that you are used to is simply a hexadecimal representation of that number. It is often chosen because they are easy to exchange as strings (128-bit integers are difficult to handle. After all, a typical integer variable usually only holds 64 bit). Consider the following examples:

  1. md5("test") in hexadecimal (base 16) representation: 098f6bcd4621d373cade4e832627b4f6
  2. md5("test") in base 64 representation: CY9rzUYh03PK3k6DJie09g==
  3. md5("test") in decimal (base 10) representation: 12707736894140473154801792860916528374
  4. md5("test") in base 27 representation (never used, just because I can and to prove my point): ko21h9o9h8bc1hgmao4e69bn6f

All these strings represent the same numerical value, just in different bases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM