开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜