Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active April 10, 2019 20:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/d10e7ac5238acc4e97053b9f8b6a27b9 to your computer and use it in GitHub Desktop.
Save miguelmota/d10e7ac5238acc4e97053b9f8b6a27b9 to your computer and use it in GitHub Desktop.
Node.js Keccak256 (SHA-3) hash of file
const fs = require('fs')
const {sha3} = require('ethereumjs-util')
const crypto = require('crypto')
const file = fs.readFileSync(__dirname + '/file.png')
const keccak256hash = sha3(file).toString('hex')
console.log(keccak256hash)
const sha256hash = crypto.createHash('sha256').update(file).digest().toString('hex')
console.log(sha256hash)
@PaulRBerg
Copy link

This is cool and works but should be updated to use keccak256 instead of sha3 as per the latest naming convention.

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