|
| 1 | +Python PKCS#5 v2.0 PBKDF2 Module |
| 2 | +-------------------------------- |
| 3 | + |
| 4 | +This module implements the password-based key derivation function, PBKDF2, |
| 5 | +specified in `RSA PKCS#5 v2.0 <http://www.rsa.com/rsalabs/node.asp?id=2127>`_. |
| 6 | + |
| 7 | +Example PBKDF2 usage |
| 8 | +==================== |
| 9 | + |
| 10 | +:: |
| 11 | + |
| 12 | + from pbkdf2 import PBKDF2 |
| 13 | + from Crypto.Cipher import AES |
| 14 | + import os |
| 15 | + |
| 16 | + salt = os.urandom(8) # 64-bit salt |
| 17 | + key = PBKDF2("This passphrase is a secret.", salt).read(32) # 256-bit key |
| 18 | + iv = os.urandom(16) # 128-bit IV |
| 19 | + cipher = AES.new(key, AES.MODE_CBC, iv) |
| 20 | + # ... |
| 21 | + |
| 22 | +Example crypt() usage |
| 23 | +===================== |
| 24 | + |
| 25 | +:: |
| 26 | + |
| 27 | + from pbkdf2 import crypt |
| 28 | + pwhash = crypt("secret") |
| 29 | + alleged_pw = raw_input("Enter password: ") |
| 30 | + if pwhash == crypt(alleged_pw, pwhash): |
| 31 | + print "Password good" |
| 32 | + else: |
| 33 | + print "Invalid password" |
| 34 | + |
| 35 | +Example crypt() output |
| 36 | +====================== |
| 37 | + |
| 38 | +:: |
| 39 | + |
| 40 | + >>> from pbkdf2 import crypt |
| 41 | + >>> crypt("secret") |
| 42 | + '$p5k2$$hi46RA73$aGBpfPOgOrgZLaHGweSQzJ5FLz4BsQVs' |
| 43 | + >>> crypt("secret", "XXXXXXXX") |
| 44 | + '$p5k2$$XXXXXXXX$L9mVVdq7upotdvtGvXTDTez3FIu3z0uG' |
| 45 | + >>> crypt("secret", "XXXXXXXX", 400) # 400 iterations (the default for crypt) |
| 46 | + '$p5k2$$XXXXXXXX$L9mVVdq7upotdvtGvXTDTez3FIu3z0uG' |
| 47 | + >>> crypt("spam", iterations=400) |
| 48 | + '$p5k2$$FRsH3HJB$SgRWDNmB2LukCy0OTal6LYLHZVgtOi7s' |
| 49 | + >>> crypt("spam", iterations=1000) # 1000 iterations |
| 50 | + '$p5k2$3e8$H0NX9mT/$wk/sE8vv6OMKuMaqazCJYDSUhWY9YB2J' |
| 51 | + |
| 52 | + |
| 53 | +Resources |
| 54 | +========= |
| 55 | + |
| 56 | +Homepage |
| 57 | + https://www.dlitz.net/software/python-pbkdf2/ |
| 58 | + |
| 59 | +Source Code |
| 60 | + https://github.com/dlitz/python-pbkdf2/ |
| 61 | + |
| 62 | +PyPI package name |
| 63 | + `pbkdf2 <http://pypi.python.org/pypi/pbkdf2>`_ |
| 64 | + |
| 65 | +License |
| 66 | +======= |
| 67 | +Copyright (C) 2007-2011 Dwayne C. Litzenberger < [email protected]> |
| 68 | + |
| 69 | +Permission is hereby granted, free of charge, to any person obtaining |
| 70 | +a copy of this software and associated documentation files (the |
| 71 | +"Software"), to deal in the Software without restriction, including |
| 72 | +without limitation the rights to use, copy, modify, merge, publish, |
| 73 | +distribute, sublicense, and/or sell copies of the Software, and to |
| 74 | +permit persons to whom the Software is furnished to do so, subject to |
| 75 | +the following conditions: |
| 76 | + |
| 77 | +The above copyright notice and this permission notice shall be |
| 78 | +included in all copies or substantial portions of the Software. |
| 79 | + |
| 80 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 81 | +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 82 | +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 83 | +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 84 | +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 85 | +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 86 | +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
0 commit comments