I was using guava 14 to do String hashing like so:
Hashing.sha256().newHasher().putString("String").hash().toString();
=>
4d1ca6dce72e20ce214b706168340683bb6b571a7c977c1a9fe029a1cc1c4d06
just upgraded to guava16,
calling this function:
Hashing.sha256().newHasher().putString("String", Charsets.UTF-8).hash().toString() gives me a different result.
=>
b2ef230e7f4f315a28cdcc863028da31f7110f3209feb76e76fed0f37b3d8580
I suspect that the old version was using default charset, but switching Charsets on guava16 doesn't give me the same result as in guava14. What did I do wrong here?
As stated in the docs of Guava 15, the replacement for the old putString(String) method is putUnencodedChars.
As Louis said, the replacement is Hasher.putUnencodedChars(). Or, you can use the shortcuts on the HashFunction interface:
Hashing.sha256().hashUnencodedChars("String").toString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With