sha1sum from commandline different from other sources

0

I have sha1sum installed on an Ubuntu 16.04 system and used it like this to compute an sha1 sum:

root@computer:# echo 1234 | sha1sum
1be168ff837f043bde17c0314341c84271047b31  -

also I computed the sum on a file whose only content was the same '1234':

root@computer:# sha1sum /tmp/x
1be168ff837f043bde17c0314341c84271047b31  /tmp/x

and I got the same answer both times. Then I went to a couple of websites that will compute sha1 hashes for you. I went to https://passwordsgenerator.net/sha1-hash-generator/ and input '1234' and got this:

7110EDA4D09E062AA5E4A390B0A572AC0D2C0220

I went to http://www.sha1-online.com and I also got

7110eda4d09e062aa5e4a390b0a572ac0d2c0220

So...how do I explain this discrepancy?

Craig

Posted 2018-03-06T03:57:33.210

Reputation: 103

Answers

1

You have a newline in the echo and file cases.

$ printf '1234' |sha1sum
7110eda4d09e062aa5e4a390b0a572ac0d2c0220  -
$ printf '1234\n' |sha1sum
1be168ff837f043bde17c0314341c84271047b31  -

user873319

Posted 2018-03-06T03:57:33.210

Reputation:

1I just discovered this, and that 'echo' has an '-n' flag to eliminate the new line: root@computer:# echo -n 1234 | sha1sum 7110eda4d09e062aa5e4a390b0a572ac0d2c0220 - – Craig – 2018-03-06T04:29:23.843