Search code examples
md5

Is MD5 Hash of current-time in milliseconds Time ordered?


I am generating a MD5 hash of current time. Example :

md5Hex(System.currentTimeMillis())

Will this be time ordered?


Solution

  • Definitely not.

    While MD5 isn't the best hash function, a fundamental property of cryptographic hash functions is that (per Wikipedia):

    "a small change to a message should change the hash value so extensively that a new hash value appears uncorrelated with the old hash value (avalanche effect)"

    For the hashes of a series of times to be time-ordered, the hash function would need to show predictable changes (consistent increases) in response to changing input (the increasing time) - and this contradicts the properties that a cryptographic hash function needs to have.