Use MessageDigest properly. Apparently it isn't thread-safe.

Added a regression test as well.