Skip to content Skip to sidebar Skip to footer

How To Calculate The Sha1 Hash Of A Blob Using Node.js Crypto

In my node.js app I would like to upload a file and calculate the sha1 . I tried the following : export function calculateHash(file, type){ const reader = new FileReader(); var

Solution 1:

if you're reading the contents in as a block, you're making this harder than it needs to be. We do this:

const fs = require('fs');
export function calculateHash(file, type){
  const testfile = fs.readFileSync(file);
  var sha1sum = crypto.createHash('sha1').update(testFile).digest("hex");
  console.log(sha1sum);
}

Post a Comment for "How To Calculate The Sha1 Hash Of A Blob Using Node.js Crypto"