1

Calculating SHA256 gives me an incorrect result when I'm using "shasum":

$ echo "abcd" | shasum -a 256
fc4b5fd6816f75a7c81fc8eaa9499d6a299bd803397166e8c4cf9280b801d62c  -

# or

$ echo abcd | shasum -a 256
fc4b5fd6816f75a7c81fc8eaa9499d6a299bd803397166e8c4cf9280b801d62c  -

And in ruby:

$ irb
irb(main):001:0> require "digest"
=> true

irb(main):005:0> Digest::SHA256.hexdigest("abcd")
=> "88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589"

Online generators give me the result as ruby does.

Why isn't the result of "shasum" correct?

4

This is because echo adds a new-line character to the end of its output, by default. Try using:

echo -n abcd | ...

instead, which suppresses the new-line at the end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.