Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message #7

Open
EklectikDesign2020 opened this issue Aug 2, 2021 · 2 comments
Open

Error message #7

EklectikDesign2020 opened this issue Aug 2, 2021 · 2 comments

Comments

@EklectikDesign2020
Copy link

After encrypt() when I want to decrypt I get a data is not a valid scrypt-encryption block

@holgern
Copy link
Owner

holgern commented Dec 3, 2021

Please provide some python example code

@bgiarrizzo
Copy link

I had the same issue here, at the decrypt step, i've got the error message :

E       UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 0: invalid start byte

Here is the code as it was used :

def generate_password_hash(password: str) -> str:
    return scrypt.encrypt(input=os.urandom(8), password=password, maxtime=0.1)


def verify_password(plain_password: str, hashed_password: bytes) -> bool:
    try:
        scrypt.decrypt(
            input=hashed_password,
            password=plain_password,
            maxtime=0.5,
        )
        return True
    except scrypt.error:
        return False

The failure happened at the decrypt step, when decoding the output bytes.

The thing i've done was to generate random 32chars string via the libs string & random, and use it as passphrase.

import string
import random

def generate_password_hash(password: str) -> str:
    passphrase = "".join(random.choice(string.ascii_lowercase) for i in range(32))
    return scrypt.encrypt(input=passphrase, password=password, maxtime=0.1)


def verify_password(plain_password: str, hashed_password: bytes) -> bool:
    try:
        scrypt.decrypt(input=hashed_password, password=plain_password, maxtime=0.5)
        return True
    except scrypt.error:
        return False

And now, no errors on the decrypt step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants