如何将文件的 md5 值包含到自身中
假设您要创建一个包含自身 md5 摘要的文件。怎么做呢? 在将 md5 值包含到文件中之前,您必须计算该值,但当且仅当 md5 摘要已包含在文件中时,您才能计算该值。这是一种两难的困境。有什么想法吗?
Supposed that you want to create a file which contains the md5 digest of itself. How to do that?
Before you include the md5 value into the file, you have to calculate the value, but if and only if the md5 digest has been included into the file, you can calculate the value. It's kind o a dilemma. Any Idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简而言之,除非您使用 MD5 漏洞,否则您无法做到这一点。我相信即使使用 MD5 漏洞构建这样的冲突也是不切实际的。解决方案是将摘要附加在文件末尾或单独发送。
The short answer is that unless you use MD5 vulnerabilities you can't do that. I believe that even using MD5 vulnerabilities building such collision is impractical. A solution would be to either attach the digest at the end of the file or ship it separately.
您必须避免这种循环依赖,因此您无法对校验和进行校验。要解决这个问题,您可以在文件中为校验和保留空间,但将该空间设置为零。然后计算校验和并将其嵌入。为了稍后检查它,您必须读入它,并再次将文件中的这些字节设置为零。
You have to avoid that cyclic dependency, so you can't checksum the checksum. To work around that, you could reserver space for the checksum in your file, but set that space to zeroes. Then calculate the checksum and embed it. In order to check it later, you'd have to read it in, and set those bytes in the file to zero again.