Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when I hash a file with Md5 what is hashed?

Tags:

md5

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?

like image 624
JayBoux Avatar asked Jul 29 '11 07:07

JayBoux


People also ask

What is MD5 hash of a file?

MD5 is primarily used to authenticate files. It's much easier to use the MD5 hash to check a copy of a file against an original than to check bit by bit to see if the two copies match. MD5 was once used for data security and encryption, but these days its primary use is authentication.

What does MD5 hashing do?

Meanwhile, MD5 is a secure hash algorithm and a cryptographic hash function that can detect some data corruption but is primarily intended for the secure encryption of data that is being transmitted and the verification of digital certificates.

What happens when you hash a file?

A message digest, or hash, is a signature that identifies some amount of data, usually a file or message. Cryptographic hashing algorithms are one-directional mathematical formulae designed to generate a unique value for every possible input-in this case, the data.

What does a MD5 hash look like?

MD5 (Message-Digest algorithm 5) is a widely used cryptographic hash function that results in a 128-bit hash value. The 128-bit (16-byte) MD5 hashes (also termed message digests) typically are represented as 32-digit hexadecimal numbers (for example, ec55d3e698d289f2afd663725127bace).


2 Answers

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!
like image 188
Charliemops Avatar answered Sep 28 '22 07:09

Charliemops


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).

like image 28
hfs Avatar answered Sep 28 '22 06:09

hfs