我目前正在尝试使用python密码库和RSA加密和解密密码。密钥生成工作正常,加密工作正常,但在解密密码时,我会遇到以下回溯错误消息:raise ValueError("Ciphertext length must be equal to key size.")
我的加密和解密代码如下所示:
^{pr2}$
运行此脚本时出错:crypter = AppCryptography()
backend_public_key = crypter.load_public_key(dir_path + "/util/keys/backend_public_key.pem")
frontend_private_key = crypter.load_private_key(dir_path + "/util/keys/frontend_private_key.pem")
encrypted_password = crypter.encrypt_password(backend_public_key, password)
signature = crypter.sign_data(frontend_private_key, password)
backend_private_key = crypter.load_private_key(dir_path + "/util/keys/backend_private_key.pem")
cleartext = crypter.decrypt(backend_private_key, encrypted_password)
stacktrace显示错误来自解密函数,但我无法看到错误在函数定义中的位置。在File "/Users/Me/anaconda/envs/flask_dream/lib/python2.7/site-packages/sqlalchemy/orm/state.py", line 411, in _initialize_instance
return manager.original_init(*mixed[1:], **kwargs)
File "/Users/Me/anaconda/envs/flask_dream/lib/python2.7/site-packages/sqlalchemy/ext/declarative/base.py", line 650, in _declarative_constructor
setattr(self, k, kwargs[k])
File "/Users/Me/Desktop/Projects/Flask-Dream/project_app/models.py", line 114, in password
cleartext = crypter.decrypt(backend_private_key, encrypted_password)
File "/Users/Me/Desktop/Projects/Flask-Dream/project_app/util/crypto.py", line 121, in decrypt
label=None
File "/Users/Me/anaconda/envs/flask_dream/lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/rsa.py", line 397, in decrypt
raise ValueError("Ciphertext length must be equal to key size.")