Skip to content

Instantly share code, notes, and snippets.

Created June 20, 2017 13:57
  • Star 46 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
NODE.JS - How to generate file's Checksum (CRYPTO)
var fs = require('fs');
var crypto = require('crypto');
fs.readFile('file.pdf', function(err, data) {
var checksum = generateChecksum(data);
function generateChecksum(str, algorithm, encoding) {
return crypto
.createHash(algorithm || 'md5')
.update(str, 'utf8')
.digest(encoding || 'hex');
Copy link

Thanks! It worked for me

Copy link

nice man!

Copy link

embarq commented Jun 2, 2020

Thanks a lot 🌮

Copy link

gurdiga commented Jul 1, 2021

Thank you! 🤓

@github — I miss a 👍 button for gists. 🙃

Copy link

Neat. Thank you!

Copy link

Thank y♂u Sir!

Copy link

how to use the output since it is printed in console?

Copy link

You could change the console.log to a return statement and have the whole fs.readFile function saved to a variable as a function expression. Then you would have your hash string in a variable to use as you wish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment