py-scrypt icon indicating copy to clipboard operation
py-scrypt copied to clipboard

documentation example about password hashing does not work

Open zx80 opened this issue 1 year ago • 1 comments

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?

zx80 avatar Aug 12 '24 11:08 zx80

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!

starryknight64 avatar Sep 17 '24 18:09 starryknight64

Is fixed now

holgern avatar Aug 05 '25 04:08 holgern