¿Cuánto dura el hash SHA256?


Voy a ejecutar SHA256 en una contraseña + salt, pero no se cuánto tiempo hacer mi VARCHAR al configurar la base de datos MySQL. ¿Qué es una buena longitud?

 185
Author: kenorb, 2010-02-11

5 answers

Un sha256 tiene 256 bits de largo as como su nombre indica.

Si está utilizando una representación hexadecimal, cada dígito codifica para 4 bits ; por lo que necesita 64 dígitos para representar 256 bits so por lo tanto, necesita un varchar(64), o un char(64), ya que la longitud es siempre la misma, sin variar en absoluto.

Y la demo :

$hash = hash('sha256', 'hello, world!');
var_dump($hash);

Te dará :

$ php temp.php
string(64) "68e656b251e67e8358bef8483ab0d51c6619f3e7a1a9f0e75838d41ff368f728"

Es decir, una cadena con 64 caracteres.

 265
Author: Pascal MARTIN,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-12-14 11:10:09

Opciones de codificación para los 256 bits de SHA256:

  1. Base64: 6 bits por carácter = CHAR(44) incluyendo el carácter de relleno
  2. Hex: 4 bits por char = CHAR(64)
  3. Binario: 8 bits por byte = BINARY(32)
 39
Author: RickNZ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-11 12:23:28

¿Por qué lo harías VARCHAR? No varía. Siempre son 64 caracteres, que se pueden determinar ejecutando cualquier cosa en una de las calculadoras en línea SHA-256.

 20
Author: ceejayoz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-02-10 23:01:48

Prefiero usar BINARIO(32) ya que es la forma optimizada!

Usted puede colocar en que 32 dígitos hexadecimales de (00 a FF).

Por lo tanto BINARIO (32)!

 20
Author: marctrem,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-07 21:20:49

Se fijarán 64 caracteres, así que use char(64)

 7
Author: noushy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-10-13 18:34:00