I am trying to use python's cryptography library to generate a password dependant key:
Both functions are coppied out of the documentation: https://cryptography.io/en/latest/hazmat/primitives/key-derivation-functions/ And for both Scrypt and PBKDF2HMAC backend is listed as an optional argument however when I run these functions I get raised:
PS D:\code\Fiver\flohar> & C:/Users/mpnlo/AppData/Local/Programs/Python/Python38-32/python.exe d:/code/Fiver/flohar/passwordManager.py
Traceback (most recent call last):
File "d:/code/Fiver/flohar/passwordManager.py", line 202, in <module>
main()
File "d:/code/Fiver/flohar/passwordManager.py", line 152, in main
key = generateKey('Password')
File "d:/code/Fiver/flohar/passwordManager.py", line 24, in generateKey
kdf = Scrypt(
TypeError: __init__() missing 1 required positional argument: 'backend'
PS D:\code\Fiver\flohar>
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.scrypt import Scrypt
def generateKey(master):
salt = b'H\x1d\tMg\xc9\xe3\xec\xbeU\xee\x03\xec\x18\xf1U'
kdf = Scrypt(
length=32,
salt=salt,
n=2**14,
r=8,
p=1,
)
return base64.urlsafe_b64encode(kdf.derive(master))
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
def generateKey(master):
salt = b'H\x1d\tMg\xc9\xe3\xec\xbeU\xee\x03\xec\x18\xf1U'
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
salt=salt,
iterations=100000,
)
return base64.urlsafe_b64encode(kdf.derive(master))
Has the module received an update that now requires backend or am I doing something wrong, when import default backends and use those or just use None for the backend argument I get an error that the backend does not support the given algorithm.
I had the wrong version of cryptography installed, thank you Topaco for pointing this out to me.