py-scrypt
py-scrypt copied to clipboard
documentation example about password hashing does not work
The example about password hashing based on using the password as a key to encode a random string does not work at all:
import os
import scrypt # 0.8.24
data = scrypt.encrypt(os.urandom(64), "secret", maxtime=0.1)
scrypt.decrypt(data, "secret", maxtime=0.1)
results in
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xef in position 1: invalid continuation byte
The library seems to assume that the encoded stuff is unicode, which is very unlikely when considering random bytes.
Note that sometime it also fails on maxtime.
Consider adding to tests the examples shown in the documentation?
Just had this same issue. If you set encoding=None in the call to decrypt then it works fine (although perhaps not always the most ideal!).
import os
import scrypt # 0.8.24
data = scrypt.encrypt(os.urandom(64), "secret", maxtime=0.1)
scrypt.decrypt(data, "secret", maxtime=0.1, encoding=None) # throws no error
Regardless, the example should be updated to work properly!
Is fixed now