21

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).

user1256821
  • 1,158
  • 3
  • 15
  • 35
  • The link above to verify SHA hash is broken. [Try this](https://fe-tool.com/en-us/hash/sha512?inputText=password) – cwtuan Oct 11 '22 at 08:10

2 Answers2

28

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.

slm
  • 15,396
  • 12
  • 109
  • 124
Dave G
  • 9,639
  • 36
  • 41
4

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
Micho
  • 928
  • 9
  • 11