Reputation: 2471
There must be something simple I am missing. I am not sure, why the SHA sums wouldn't match. The sums are generated with nodejs
and shasum
on Linux command line.
user@host:~$ nodejs
> var c = require('crypto')
undefined
> c.createHash('sha1').update('Hello world!','ascii').digest('hex')
'd3486ae9136e7856bc42212385ea797094475802'
user@host:~$ shasum -
Hello world!
47a013e660d408619d894b20806b1d5086aab03b -
I did try with different options such as ascii
and utf-8
with nodejs
and shasum
; but, mismatch exists. Of course, for simple English text, ascii
and utf-8
shouldn't matter.
Although, since the applications generating and using the hashes will be nodejs
applications; and, so, it probably wouldn't matter. But, I cannot get around the fact that the sums would be different.
Can you please guide me ?
Upvotes: 1
Views: 654
Reputation: 13226
Your shasum
is getting an extra new line character (\n
).
$ echo Hello world! | shasum
47a013e660d408619d894b20806b1d5086aab03b -
-------------------------------------------
$ node
> var c = require('crypto')
undefined
> c.createHash('sha1').update('Hello world!').digest('hex')
'd3486ae9136e7856bc42212385ea797094475802'
> c.createHash('sha1').update('Hello world!\n').digest('hex')
'47a013e660d408619d894b20806b1d5086aab03b'
Upvotes: 2