Fast PBKDF2 for Python 2.6 - 3.4
This is a backport of hashlib.pbkdf2_hmac for Python 2.6 to 2.7. The implementation comes with a pure Python implementation and a C module that depends on OpenSSL. The C code does not wrap PKCS5_PBKDF2_HMAC as its implementation is suboptimal.
>>> from backports.pbkdf2 import pbkdf2_hmac, compare_digest >>> dkey = pbkdf2_hmac('sha1', passwordbytes, saltbytes, iterations=100000) >>> compare_digest(dkey, originalkey) True
pbkdf2_hmac(hash_name, password, salt, iterations, dklen=None)
- name of the digest algorithm as string
- password as bytes, bytearray or bytes-like object (*)
- salt as bytes, bytearray or bytes-like object (*). The salt should be generated with a CPRNG like os.urandom(). You should never use random.random(). About 16 bytes seem to be a good choice.
- number of rounds, 100,000 rounds of SHA-1 take about 30ms on a modern CPU.
- length of the derived key (defaults to digest_size)
- derived key as bytes
(*) bytearray and bytes-like objects are not supported on Python 2.6
|Django pbkdf2 1.5.4||1.976||2.430||2.676||3.078|
- number of runs per test
- Python 3.3 on Linux AMD64
- Intel i7-2860QM @ 2.50GHz
Release date: 19-Oct-2013
- initial release of backports.pbkdf2
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.