恢复下载的MD5摘要 [英] MD5 digest of a resumed download

查看:75
本文介绍了恢复下载的MD5摘要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从http服务器下载文件,并且必须考虑下载过程中的随机时间,网络连接失败或计算机崩溃.如果发生这种情况,我将使用HTTP"Range:"标头开始恢复下载.

I am downloading a file from an http server and have to take into account that at a random point during download, the network connection fails, or the computer crashes. If that happens, I start a resume download using the HTTP "Range:" header.

由于必须根据MD5哈希对下载进行验证,因此似乎没有办法让我在简历后使用网络输入流来获取正确的哈希,因为java.security.MessageDigest似乎没有该方法基本上说从我先前下载的部分md5哈希开始更新当前的md5哈希".

Since the download must be validated against an MD5 hash, there seems to be no way for me to use the network inputstream after a resume to get the correct hash, since java.security.MessageDigest doesn't seem to have method that basically says "start upating the current md5 hash from this partial md5 hash that I have from the previous download".

我对md5的内幕不是很熟悉-从理论上讲这是可能的,并且有一个允许我这样做的库吗?

I am not very familiar with the innards of md5 - would this be theoretically possible and is there a library that lets me do that?

从下载的文件中计算md5哈希值将是非常昂贵的性能.

Computing the md5 hash from the downloaded file would be prohibitvely expensive performance wise.

推荐答案

您可以在向MD5馈送网络流之前,向MD5提供要恢复的文件的内容.

You can feed the MD5 with the content of the file you are resuming from prior to feeding it the network stream.

如果您自己实现了MD5,则可以将状态保存在部分下载的文件中,然后从那里继续MD5计算.例如,使用此MD5实现它应该与在com.twmacinta.util.MD5中保存/加载com.twmacinta.util.MD5State state一样简单.关于您的评论,请注意,本机实现是完全可选的,并且应在纯Java中运行.这是来自

If you implemented MD5 on your own you could save the state along the partially downloaded file and also resume the MD5 calculation from there. For example using this MD5 implementation it should be as simple as saving/loading the com.twmacinta.util.MD5State state inside com.twmacinta.util.MD5. Regarding your comment, note that the native implementations is completely optional and it should work in pure Java. Here is a quote from the documentation:

当适当的本机库可用时,此类将尝试使用本机方法快速计算校验和[…]如果找不到该库,则代码将退回到默认的(较慢的)Java代码.
This class will attempt to use a native method to quickly compute checksums when the appropriate native library is available […] If the library is not found, the code will fall back to the default (slower) Java code.

这篇关于恢复下载的MD5摘要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆