I'm trying to port a Python script to Node and I've become stuck on SHA1 hashes.
The following Python code:
import hashlib
user = 'test'
ret = hashlib.sha1(user.encode('utf-8')).digest()
print(ret);
Prints out:
b'\xa9J\x8f\xe5\xcc\xb1\x9b\xa6\x1cL\x08s\xd3\x91\xe9\x87\x98/\xbb\xd3'
I need a SHA1 hash in this format in Node. This Javascript:
var crypto = require('crypto');
var generator = crypto.createHash('sha1');
generator.update(new Buffer('test'));
console.log(generator.digest('binary'));
prints
©Jå̱sÓé/»Ó
How can I get Node to produce the output in the same style as Python does? It's clearly not binary or hex, what format is the python output in?
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3. The JavaScript output is the Latin-1 encoding of those bytes.\xa9is©in iso-8859-1 encoding. You second string just seems to be truncated.