Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP crypt() - Returned md5 hash

Tags:

php

md5

crypt

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, a-f), right?

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

like image 484
Tream Avatar asked Mar 31 '26 19:03

Tream


1 Answers

Normally it should be a 32 char string (0-9, a-f), 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.

like image 79
helmbert Avatar answered Apr 03 '26 08:04

helmbert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!