Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenSSL create SHA hash from shell stdin

How to generate the SHA-512 hash with OpenSSL from command line without using a file?

I've tried this

echo "password" | openssl dgst -sha512

but the hash looks wrong (compared with http://hash.online-convert.com/sha512-generator).

like image 773
user1256821 Avatar asked Jun 16 '12 18:06

user1256821


2 Answers

Try echo -n "password".

What's happening is the new line character(s) that echo adds to the end of the string are getting hashed. The -n to echo suppresses this behavior.

like image 184
Dave G Avatar answered Nov 05 '22 17:11

Dave G


If you're using MacOS, you might stumble upon a case where the echo is ignoring the -n argument. To workaround that, call the binary directly:

/bin/echo -n "password" | openssl sha512
like image 25
Micho Avatar answered Nov 05 '22 15:11

Micho