Python 3 encrypt/decrypt with bytes

Issue #10 invalid
Manuel Barkhau
created an issue

scrypt.decrypt implicitly decodes the string with the utf-8 encoding, which means it can't decrypt bytes which were previously encrypted.

Ideally one could get the same output type as was put in.

import os
from scrypt import encrypt, decrypt 

data = "string".encode('utf-8')
print(type(data))  # <class 'bytes'>

edata = encrypt(data, "secret", 0.1)
data =  decrypt(edata,  "secret")
print(type(data))  # <class 'str'>

data = os.urandom(1000)
print(type(data))  # <class 'bytes'>

edata = encrypt(data, "secret", 0.1)
data =  decrypt(edata,  "secret")  # raises UnicodeDecodeError

Alternatively the decrypt function might get an encoding parameter which is "utf-8" by default and can be set to None of <class 'bytes'> are to be returned.

Comments (4)

  1. Manuel Barkhau reporter

    It might be reasonable to update the docstring though. Even if the PyPI version were current, I don't think I could have seen that it takes the additional parameter.

  2. Log in to comment