I am creating a hash of an auto-incrementing number. I have created two example loops of how I'm trying to achieve this.
When #1 is is run, the first hash is logged to the console and on the second iteration through the loop, the following error is returned. Error: Digest already called
I believe this is due to this reference in the documentation: The Hash object can not be used again after hash.digest() method has been called. Multiple calls will cause an error to be thrown.
How can I create a loop that uses Node's crypto library to create multiple hashes at one time?
// Reproduce #1
const crypto = require('crypto');
const hash = crypto.createHash('sha256');
for (let i = 0; i < 5; i++) {
hash.update('secret' + i);
console.log(hash.digest('hex'));
}