简体   繁体   English

PHP crypt() - 返回md5哈希

[英]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: crypt()函数的文档( http://php.net/manual/de/function.crypt.php )显示了MD5哈希的以下示例:

$1$rasmusle$rISCgZzpwk3UhDidwXvin0

I understand, that "$1$" is the prefix, which contains the information, that the hash is an MD5 hash. 我理解,“$ 1 $”是前缀,其中包含哈希是MD5哈希的信息。

But how is the rest of the string an MD5 hash? 但是字符串的其余部分如何是MD5哈希? Normally it should be a 32 char string (0-9, af), right? 通常它应该是一个32字符串(0-9,af),对吧?

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? 通常它应该是一个32字符串(0-9,af),对吧?

That is not correct (at least strictly speaking). 这是不正确的 (至少严格来说)。 Technically, a MD5 hash is a 128 bit numeric value . 从技术上讲,MD5哈希值是128位数值 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). 通常选择它是因为它们很容易作为字符串交换 (128位整数很难处理。毕竟,典型的整数变量通常只能保持64位)。 Consider the following examples: 请考虑以下示例:

  1. md5("test") in hexadecimal (base 16) representation: 098f6bcd4621d373cade4e832627b4f6 十六进制 (基数为16)表示的md5("test")098f6bcd4621d373cade4e832627b4f6
  2. md5("test") in base 64 representation: CY9rzUYh03PK3k6DJie09g== 基础64表示的md5("test")CY9rzUYh03PK3k6DJie09g==
  3. md5("test") in decimal (base 10) representation: 12707736894140473154801792860916528374 md5("test") in decimal (base 10)表示: 12707736894140473154801792860916528374
  4. md5("test") in base 27 representation (never used, just because I can and to prove my point): ko21h9o9h8bc1hgmao4e69bn6f 基础27表示的md5("test") (从未使用过,只因为我可以证明我的观点): ko21h9o9h8bc1hgmao4e69bn6f

All these strings represent the same numerical value, just in different bases. 所有这些字符串代表相同的数值,只是在不同的基础上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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