What does resetting MessageDigest do?

215 views Asked by At

Here is the code I'm talking about:

md.reset();

What does the reset() method do to the MessageDigest object? Why is it necessary?

1

There are 1 answers

0
Thilo On

It returns the MessageDigest instance back to its initial state, so that you can use it again for calculating another message digest (as opposed to getting a new instance, which could be expensive or inconvenient).

If you did not call this method, but continued to just shove the second message in, the resulting digest might not be correct (as it could contain "junk" left over from the previous calculation).