when I hash a file with Md5 what is hashed?

谁说我不能喝 提交于 2019-12-04 01:22:31

问题


is it just the file contents that get hashed? Is there any way to include the file name and or metadata such as creation date into the hashing process?


回答1:


In general, all the file hashers encrypts only the binary content of the file.

You can prove this with the following process:

  1. Apply the md5 algorithm to a file
  2. Copy this file into other directory and change its name.
  3. Apply the md5 algorithm to the copy.
  4. Compare both of the results. They are equal!



回答2:


MD5 tools will generally work with the binary content of the file. But you are of course free to put the file name and modification time into the content that gets hashed as well. E.g.

(stat -c %Y filename; echo filename; cat filename) | md5sum

Of course to verify the hash sum you have to use the exact same procedure, or else your hash sums will differ (e.g. when using different date formats).



来源:https://stackoverflow.com/questions/6869880/when-i-hash-a-file-with-md5-what-is-hashed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!