Skip to content

Instantly share code, notes, and snippets.

@AlloVince
Last active May 25, 2022 17:46
Show Gist options
  • Save AlloVince/ecbc50d3ee09965813ead9e34ca292f1 to your computer and use it in GitHub Desktop.
Save AlloVince/ecbc50d3ee09965813ead9e34ca292f1 to your computer and use it in GitHub Desktop.
Compatible sha256 file hash for python and node.js
const crypto = require('crypto');
const fs = require('fs')
const fileBuffer = fs.readFileSync(filePath);
const fsHash = crypto.createHash('sha256');
fsHash.update(fileBuffer);
const hash = fsHash.digest('hex');
console.log(hash);
import hashlib
with open(file_path, mode='rb') as file:
file_content = file.read()
hash = hashlib.sha256(file_content).hexdigest()
print(hash)
@blaine-foreflight
Copy link

THANK YOU!!!!

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