File containing its own checksum

后端 未结 12 1710
误落风尘
误落风尘 2020-12-23 13:16

Is it possible to create a file that will contain its own checksum (MD5, SHA1, whatever)? And to upset jokers I mean checksum in plain, not function calculating it.

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-23 13:59

    Sure, you could concatenate the digest of the file itself to the end of the file. To check it, you would calculate the digest of all but the last part, then compare it to the value in the last part. Of course, without some form of encryption, anyone can recalculate the digest and replace it.

    edit

    I should add that this is not so unusual. One technique is to concatenate a CRC-32 so that the CRC-32 of the whole file (including that digest) is zero. This won't work with digests based on cryptographic hashes, though.

提交回复
热议问题