为什么 python 关键导数函数 'requiring' 是可选参数:后端?
Why are python key derivative functions 'requiring' an optional argument: backend?
我正在尝试使用 python 的加密库来生成密码相关密钥:
这两个函数都从文档中复制出来:https://cryptography.io/en/latest/hazmat/primitives/key-derivation-functions/
对于 Scrypt 和 PBKDF2HMAC 后端都被列为可选参数,但是当我 运行 这些函数时,我得到了:
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))
模块是否收到现在需要后端的更新,或者我做错了什么,当导入默认后端并使用它们或仅使用 None 作为后端参数时,我收到后端不支持的错误支持给定的算法。
我安装了错误的加密版本,谢谢 Topaco 向我指出了这一点。
我正在尝试使用 python 的加密库来生成密码相关密钥:
这两个函数都从文档中复制出来:https://cryptography.io/en/latest/hazmat/primitives/key-derivation-functions/ 对于 Scrypt 和 PBKDF2HMAC 后端都被列为可选参数,但是当我 运行 这些函数时,我得到了:
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))
模块是否收到现在需要后端的更新,或者我做错了什么,当导入默认后端并使用它们或仅使用 None 作为后端参数时,我收到后端不支持的错误支持给定的算法。
我安装了错误的加密版本,谢谢 Topaco 向我指出了这一点。