Calculating a hash (md5, sha1) with an intermediate state

Viewed 123

The service receives files from clients by chunks. One chunk per request. Chunks are saved to storage. After upload-complete-request they are collected into a single file and it is necessary to check the checksum.

I need to calculate the hash of the first chunk and save state of the hash function. Then, when the next chunk is received, get the saved state of the hash function at the previous stage and calculate the hash of the next chunk, and so on. Thus, we get the hash of the entire file as if it came as a single one. The state of the hash function is planned to be stored as an attribute of the multipart upload.

The problem is that the service is a stateless. And an intermediate state of the hash function is required after calculating the hash of each chunk, and then initializing the new hash function with the previous state.

I tried to do it with java.security.MessageDigest, Guava, but do not allow to get this state and initialize new computation with the previous state.

Is there a way to do this?

0 Answers
Related