Skip to content

Instantly share code, notes, and snippets.

Embed
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);
console.log(checksum);
});
function generateChecksum(str, algorithm, encoding) {
return crypto
.createHash(algorithm || 'md5')
.update(str, 'utf8')
.digest(encoding || 'hex');
}
@djuretic
Copy link

djuretic commented Sep 28, 2018

Thanks! It worked for me

@rodrigoagostin
Copy link

rodrigoagostin commented Jan 20, 2020

nice man!

@embarq
Copy link

embarq commented Jun 2, 2020

Thanks a lot 🌮

@gurdiga
Copy link

gurdiga commented Jul 1, 2021

Thank you! 🤓

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

@Disorrder
Copy link

Disorrder commented Sep 13, 2021

Neat. Thank you!

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