我有以下函数调用 scrypt()
来自 hashlib
使用Python 3.7.9:
def aes_encrypt(msg, passwordStr):
kdfSalt = urandom(16) # 16 bytes == 128 bits
hashedKey = scrypt(passwordStr.encode(),salt=kdfSalt,n=16384,r=16,p=1, dklen=64) # 64 octets = 512 bits
当该代码运行时,我会收到错误:
File "aes_scrypt_hmac.py", line 69, in <module>
main()
File "aes_scrypt_hmac.py", line 38, in main
print(aes_encrypt(sampleData,testPassword))
File "aes_scrypt_hmac.py", line 18, in aes_encrypt
hashedKey = scrypt(passwordStr.encode(),salt=kdfSalt,n=16384,r=16,p=1, dklen=64)
ValueError: Invalid parameter combination for n, r, p, maxmem.
我已经阅读 MaxMem 在文档中未提及的特定要求(例如 0
是什么意思?以及RFC中的测量单位是什么)。
I have the following function call to scrypt()
from hashlib
using Python 3.7.9:
def aes_encrypt(msg, passwordStr):
kdfSalt = urandom(16) # 16 bytes == 128 bits
hashedKey = scrypt(passwordStr.encode(),salt=kdfSalt,n=16384,r=16,p=1, dklen=64) # 64 octets = 512 bits
When this code runs, I get the error:
File "aes_scrypt_hmac.py", line 69, in <module>
main()
File "aes_scrypt_hmac.py", line 38, in main
print(aes_encrypt(sampleData,testPassword))
File "aes_scrypt_hmac.py", line 18, in aes_encrypt
hashedKey = scrypt(passwordStr.encode(),salt=kdfSalt,n=16384,r=16,p=1, dklen=64)
ValueError: Invalid parameter combination for n, r, p, maxmem.
I have read the documentation for scrypt, and it does not specify the expectations for the parameters; though it does link to the RFC and these params seem valid. maxmem
's specific requirement is not mentioned in the documentation (e.g. what does 0
mean? And what the unit of measurement is) or in the RFC.
发布评论
评论(1)
我必须承认,我不确定您打算使用哪种API。根据Scrypt的Python软件包,API为
genterpt
,解密
和hash
,您正在使用我找不到的东西。您的方法被命名为
加密
,但是该变量被称为hashedkey
,因此我不确定您是否在哈希或加密,这些显然是不同的。但是,这些参考可能会有所帮助。
https://github.com/holgern/py-scrypt/blob/master/scrypt/scrypt/scrypt.py”
scrypt 软件包的脚本,一切都对我有用:
GO的Scrypt软件包手册:
I have to admit I'm not sure which API you plan on using. According to scrypt's python package, the APIs are
encrypt
,decrypt
andhash
, and you are using something I can't find.Your method is named
encrypt
, but the variable is calledhashedKey
, so I'm not sure if you are hashing or encrypting, and those are obviously different.However, these references might help.
scrypt's python package implementation:
When I run the following script using Python3 and the PyPi
scrypt
package, everything works for me:Go's scrypt package manual: