I tried to get a SHA1 hash for a unicode string, some chinese string
in Android Java code in Eclipse. I used the usual MessageDigest class
and some Hex conversion piece of code from web.
I wonder how to verify that the hash and its hex conversion are correct?
I inserted that chinese string to a number of online hash converters, but
all of them produced a different hash. The same coverters work fine with
ascii strings.
I am newbie in this, so some pointers would be appreciated!
br, perza
What counts as “correct”? Hashes such as SHA-1 deal with binary data, not text… and there are various different ways of converting from text to binary.
What’s the purpose here? Do you have to make the hash match what some other code produces? If so, find out what encoding that other code uses to convert text to binary. If it’s only got to match your code, you have a free hand – I’d suggest using either UTF-8 or UTF-16, both of which are guaranteed to be present in Java, commonly available on other platforms for future options, and cover the whole of the Unicode character repertoire.