Scrypt

Last modified: 2023-08-06

Cryptography Key Derivation Function

Scrypt is a password-based key derivation function.

Using Scrypt in Python

We can use scrypt easily thanks of Pycryptodome.
We need to install it first.

pip install pycryptodome

Below is a Python script to derive a key from a password with scrypt.

from Crypto.Protocol.KDF import scrypt
from Crypto.Random import get_random_bytes

password = b'secret'
salt = get_random_bytes(16)
key = scrypt(password, salt, 16, N=2**14, r=8, p=1)
print(f"key: {key.hex()}")