To hash a payload with nodejs, I can use the crypto module and do:
const crypto = require('crypto');
const payload = "abc123";
const hashObj = crypto.createHash('sha256');
const res = hashObj.update(payload).digest('hex');
Now say I want to hash a second payload, could I safely reuse the hashObj
I just instantiated and call update
and digest
on it with the new payload? Or do I have to call createHash
for every payload?
Edit: To clarify, by reuse I mean extending the above code to the following for example:
const crypto = require('crypto');
const payload1 = "abc123";
const payload2 = "def456";
const hashObj = crypto.createHash('sha256');
const res1 = hashObj.update(payload1).digest('hex');
const res2 = hashObj.update(payload2).digest('hex');