Hashing issue between guava versions

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.

 

 

http://stackoverflow.com/questions/21287714/hashing-issue-between-guava-versions

Leave a Reply

Your email address will not be published. Required fields are marked *