Generar un sha256 desde la línea de comandos de Linux [cerrado]
Sé que la cadena "foobar" genera el hash SHA 256 c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2
usando
http://hash.online-convert.com/sha256-generator
Sin embargo, la línea de comandos shell:
hendry@x201 ~$ echo foobar | sha256sum
aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f -
Genera un hash diferente. ¿Qué me estoy perdiendo?
6 answers
echo
normalmente generará una nueva línea, que se suprime con -n
. Prueba esto:
echo -n foobar | sha256sum
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
2015-06-03 02:46:20
Si ha instalado openssl
, puede utilizar:
echo -n "foobar" | openssl dgst -sha256
Para otros algoritmos puede reemplazar -sha256
con -md4
, -md5
, -ripemd160
, -sha
, -sha1
, -sha224
, -sha384
, -sha512
o -whirlpool
.
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
2014-04-12 07:48:15
Si el comando sha256sum no está disponible (en mavericks, por ejemplo), puede usar:
echo -n "foobar" | shasum -a 256
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
2014-01-30 17:37:01
echo -n
funciona y es poco probable que desaparezca debido al uso histórico masivo, sin embargo, según las versiones recientes de el estándar POSIX , las nuevas aplicaciones conformes son " alentadas a usar printf
".
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-07-28 23:48:14
Creo que echo
produce una nueva línea final. Intente usar -n
como parámetro para hacer eco para omitir la nueva línea.
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-07-28 23:43:44
Echo produce un carácter de nueva línea final que también es hash. try:
/bin/echo -n foobar | sha256sum
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-07-28 23:44:54