dlitz / python-pbkdf2 Goto Github PK
View Code? Open in Web Editor NEWPython PKCS#5 v2.0 PBKDF2 Module
Home Page: https://www.dlitz.net/software/python-pbkdf2/
Python PKCS#5 v2.0 PBKDF2 Module
Home Page: https://www.dlitz.net/software/python-pbkdf2/
Potentially overkill.
Now that SHA-1 has a confirmed collision in the wild (thanks, Google), for security/compliance purposes the default hash algorithm should be upgraded to SHA-256.
I think users expect crypt("hi", "mom", iterations=1)
to return the hash value as the 192-bit PBKDF2 result for PBKDF2("hi", "mom", iterations=1)
but it does not.
Instead, the actual salt value used in crypt("hi", "mom", iterations=1)
is not "mom" but is rather the value "$p5k2$1$mom".
b64encode(PBKDF2("hi", "mom", iterations=1).read(24),"./")
'dRUSa0XKUkjbqg5NOyaNy9t4F1fXTQ6T'crypt("hi", "mom", iterations=1)
'$p5k2$1$mom$7e7fV91gTM4ceXPmLUMU45GSLvyPc2Vt'b64encode(PBKDF2("hi", "**$p5k2$1$**mom", iterations=1).read(24),"./")
'7e7fV91gTM4ceXPmLUMU45GSLvyPc2Vt'
patch starting at line 276 sends only the salt to PBKDF2() rather than the salt plus all the decoration that comes before it:
if iterations is None or iterations == 400:
iterations = 400
# salt = "$p5k2$$" + salt
rc = "$p5k2$$" + salt
else:
# salt = "$p5k2$%x$%s" % (iterations, salt)
rc = "$p5k2$%x$%s" % (iterations, salt)
rawhash = PBKDF2(word, salt, iterations).read(24)
# return salt + "$" + b64encode(rawhash, "./")
return rc + "$" + b64encode(rawhash, "./")
after patching you see the returned hash is the expected value:
crypt("hi", "mom", iterations=1)
'$p5k2$1$mom$dRUSa0XKUkjbqg5NOyaNy9t4F1fXTQ6T'
I need to use space char (" ") in the 'salt' parameter (PBKDF2.crypt()) to generate a PBKDF2 key for an specific purpose. On my machine, I've already changed this code (line #271) and the tests has finished with status OK.
The line 271 became like that (space is the last char):
allowed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./ "
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.