Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Convert a Picture into a Sha256 Hash Python

Tags:

python

Is it possible to input a picture into the sha256 feature of hashlib and have it spit out a hash using Python?

like image 917
MagicMarker Avatar asked Oct 20 '25 18:10

MagicMarker


1 Answers

Maybe this helps? Link

You have to import hashlib, open the file, and then calculate the hash.

import hashlib

filename = "Filepath to image file.png"
with open(filename,"rb") as f:
    bytes = f.read() # read entire file as bytes
    readable_hash = hashlib.sha256(bytes).hexdigest();
    print(readable_hash)
like image 149
JaFizz Avatar answered Oct 23 '25 07:10

JaFizz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!