mitsuhiko / python-pbkdf2

Because pbkdf2 is awesome and bcrypt is overkill
Other
149 stars 29 forks source link

Can't handle unicode strings #7

Closed joshmreesjones closed 8 years ago

joshmreesjones commented 8 years ago

I can't seem to hash unicode string with PBKDF2. Example:

from pbkdf2 import pbkdf2_bin
import os

pbkdf2_bin(u'passw0rd1', os.urandom(24))

The error:

TypeError: character mapping must return integer, None or unicode

Maybe I'm misunderstanding something about the format of unicode strings, but I hope this can be supported in the future if possible.

joshmreesjones commented 8 years ago

It turns out that HMAC not supporting Unicode is a feature. http://stackoverflow.com/questions/20849805/python-hmac-typeerror-character-mapping-must-return-integer-none-or-unicode

To fix the problem, I assumed UTF-8 passwords, set the character encoding on the webpage, converted the Unicode strings to UTF-8 strings in Flask, and passed that UTF-8 password to PBKDF2. It worked.