You only need to call reset
if you have already used that instance of MessageDigest
. reset
is being called here to clear all previous settings.
MessageDigest.getInstance
is a factory method rather than a singleton so has significant overhead attached.
From MessageDigest.getInstance:
A new MessageDigest object encapsulating the MessageDigestSpi implementation from the first Provider that supports the specified algorithm is returned.
So better to re-use and avoid the overhead of calling MessageDigest.getInstance
again.