Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何防止有人在cryptography.fernet包中打印解密的密码_Python_Sqlalchemy_Cryptography_Fernet - Fatal编程技术网

Python 如何防止有人在cryptography.fernet包中打印解密的密码

Python 如何防止有人在cryptography.fernet包中打印解密的密码,python,sqlalchemy,cryptography,fernet,Python,Sqlalchemy,Cryptography,Fernet,我是这个模块的新手,如果我的问题听起来很傻,请原谅。我正在创建一个应用程序,并使用cryptography.fernet加密MySQL凭据 例如,如果我加密并得到这个 from cryptography.fernet import Fernet key = b'PCHl_MjGyEyBxLYha3S-cWg_SDDmjT4YYaKYh4Z7Yug=' cipher_suite = Fernet(key) ciphered_text = cipher_suite.encrypt(b"SQ

我是这个模块的新手,如果我的问题听起来很傻,请原谅。我正在创建一个应用程序,并使用cryptography.fernet加密MySQL凭据

例如,如果我加密并得到这个

from cryptography.fernet import Fernet
key = b'PCHl_MjGyEyBxLYha3S-cWg_SDDmjT4YYaKYh4Z7Yug='
cipher_suite = Fernet(key)
ciphered_text = cipher_suite.encrypt(b"SQLShack@DemoPass")   
print(ciphered_text)
如果我必须对密码进行如下解密,我如何防止最终用户简单地打印密码?他们可以只打印打印(未加密的文本)。此外,将密码保存到数据库也无法达到目的,因为我的密码用于数据库。感谢您在高级课程中的帮助

key = b'PCHl_MjGyEyBxLYha3S-cWg_SDDmjT4YYaKYh4Z7Yug='
cipher_suite = Fernet(key)
ciphered_text = b'gAAAAABd_jcLWEz-fIBt3y2P3IoB3jGdbNnSzeSINZ8BomP9DrKIX2YF4pMLkMCvCxLshmKgKXk7np42xop6QIaiawbhjGayMU0UrbTeUX-6XA8zmo55vwA='
unciphered_text = (cipher_suite.decrypt(ciphered_text))
我只想在我的代码中这样做

try:
  engine = create_engine('mysql+mysqlconnector://root:encrypted_password@encrypted_host:3306/encrypted_databsed?auth_plugin=mysql_native_password')

except engine.closed():
    print("Failed to create engine")
如果我必须像下面那样解密密码,如何防止最终用户简单地打印出密码

事实上,你不能

我正在创建一个应用程序,并使用cryptography.fernet加密MySQL凭据

理论上,您可以编写一个返回数据库连接而不是明文密码的库。然而,一旦你在同一个地方(在客户端)有了密文和密钥,没有任何东西可以阻止客户端解密和打印明文