Encode unicode string before hashing, esp for Python 3 compat.