Encode string before hashing to work with Python 3.