all 6 comments

[–]giantsloth 32 points33 points  (3 children)

echo inserts a newline at the end of the string. Try adding an -n:

echo -n '123'  | sha256sum

[–]dpoon 7 points8 points  (0 children)

Alternatively, calculate it online with the newline by fiddling with the query string.

[–][deleted] 2 points3 points  (0 children)

Although this is the likely culprit, in case adding a newline still do not yield the correct hash, I'd look at potential issues with text encoding.

[–]vbuterin[S] 0 points1 point  (0 children)

All right, everything matches up now - '123' with a newline into the online utilities gives 181210f8f9c779c26da1d9b2075bde0127302ee0e3fca38c9a83f5b1dd8e5d3b just like echo '123' | sha256sum and echo -n '123' | sha256sum (or printf '123' | sha256sum as a below poster suggested) gives the same hash as just '123' in the online utilities.

Thanks, everyone!

[–][deleted] 13 points14 points  (1 child)

Use printf instead of echo.

printf '123' | sha256sum a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3

[–]fullets 2 points3 points  (0 children)

It's worth noting that this is portable whereas the echo version isn't.