X-Git-Url: https://www.wagner.pp.ru/gitweb/?p=oss%2Fctypescrypto.git;a=blobdiff_plain;f=ctypescrypto%2Fpbkdf2.py;h=2a2125af9f802b6532c3911d4f4cf7623aa0f29f;hp=bde567b5e361e119758ef0e7037a073ceb6bb519;hb=968dd1b70b51b9df1a5ee3f7c6d1645a536fb7e0;hpb=305f347018c18fa4183f8ec76177336881b713c9 diff --git a/ctypescrypto/pbkdf2.py b/ctypescrypto/pbkdf2.py index bde567b..2a2125a 100644 --- a/ctypescrypto/pbkdf2.py +++ b/ctypescrypto/pbkdf2.py @@ -4,7 +4,7 @@ PKCS5 PBKDF2 function. """ from ctypes import c_char_p, c_int, c_void_p, create_string_buffer -from ctypescrypto import libcrypto +from ctypescrypto import libcrypto, chartype from ctypescrypto.digest import DigestType from ctypescrypto.exception import LibCryptoError @@ -25,7 +25,11 @@ def pbkdf2(password, salt, outlen, digesttype="sha1", iterations=2000): """ dgst = DigestType(digesttype) out = create_string_buffer(outlen) - res = libcrypto.PKCS5_PBKDF2_HMAC(password, len(password), salt, len(salt), + if isinstance(password,chartype): + pwd = password.encode("utf-8") + else: + pwd = password + res = libcrypto.PKCS5_PBKDF2_HMAC(pwd, len(pwd), salt, len(salt), iterations, dgst.digest, outlen, out) if res <= 0: raise LibCryptoError("error computing PBKDF2")