Hash Code and Checksum - what's the difference?

后端 未结 13 1770
天命终不由人
天命终不由人 2020-12-04 07:29

My understanding is that a hash code and checksum are similar things - a numeric value, computed for a block of data, that is relatively unique.

i.e. The pr

13条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 07:54

    There is a different purpose behind each of them:

    • Hash code - designed to be random across its domain (to minimize collisions in hash tables and such). Cryptographic hash codes are also designed to be computationally infeasible to reverse.
    • Check sum - designed to detect the most common errors in the data and often to be fast to compute (for effective checksumming fast streams of data).

    In practice, the same functions are often good for both purposes. In particular, a cryptographically strong hash code is a good checksum (it is almost impossible that a random error will break a strong hash function), if you can afford the computational cost.

提交回复
热议问题