How to calculate sha1 hash for image
Hi i am trying to calculate sha1 hash for image.
Is there any function available to calulate hash of image directly?
Sorry i forgot to mention .. its in c++ i开发者_如何转开发 am trying.
Read the image file into memory, then call the SHA1 function on that. Python:
from hashlib import sha1
h = sha1(open(image_file, 'rb').read()).hexdigest()
This will give you the SHA1 of the image, including the headers, comments, etc. that are stored with it in the file. Remember that SHA1 just transforms a string of bits to a different, fixed-size string of bits. There's nothing magical about images as far as it is concerned.
EDIT: ok, C++. Get hashlib2plus, construct a sha1wrapper
, feed it the image block-by-block using updateContext
and finally hashIt
.
精彩评论