문제

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();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top