Reputation: 9206
Why after executing the command openssl sha1 < /dev/null | wc --bytes
the output is 50? The output size of SHA-1 should have 160 bits what gives us 20 bytes.
Upvotes: 3
Views: 1667
Reputation: 96937
If you want the raw, unformatted bytes, pipe the hexadecimal-formatted output from OpenSSL to xxd -r -p
, to convert that representation to raw bytes.
For example, to make a Base64-encoded SHA-1 digest of the string foo
:
$ echo "foo" | openssl sha1 | xxd -r -p | base64
8dLS+STphqyG/fezbJS83zK+7BU=
Or to simply validate the message length:
$ echo "foo" | openssl sha1 | xxd -r -p | wc --bytes
20
Upvotes: 2
Reputation: 38247
Why is the output of openssl sha1 < /dev/null | wc --bytes
50?
$ openssl sha1 < /dev/null
(stdin)= da39a3ee5e6b4b0d3255bfef95601890afd80709
Because the 20 byte digest is prefixed by (stdin)=
and is expressed in hex.
Upvotes: 6