我是这个模块的新手,如果我的问题听起来很傻,请原谅。我正在创建一个应用程序,并使用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")
事实上,你不能
理论上,您可以编写一个返回数据库连接而不是明文密码的库。然而,一旦你在同一个地方(在客户端)有了密文和密钥,没有任何东西可以阻止客户端解密和打印明文
相关问题 更多 >
编程相关推荐