我知道如何将用户输入保存到文本文件,但我该如何加密呢?这是我将用户输入保存到文本文件的方法。我尝试了 f.encrypt("Passwords_log.txt"
但没有结果
import time
password1 = input("Please type a password: ")
print("Your password has passed the verification!")
time.sleep(1)
print("Saving and encrypting password...")
time.sleep(2)
f=open("Passwords_log.txt",'a')
f.write(password)
f.write('\n')
f.close()
print("Done!")
最佳答案
有一些处理密码学的 Python 包值得一试。
cryptography
的一个简单示例如下:
from cryptography.fernet import Fernet
key = Fernet.generate_key()
cipher_suite = Fernet(key)
cipher_text = cipher_suite.encrypt(b"A really secret message. Not for prying eyes.")
plain_text = cipher_suite.decrypt(cipher_text)
关于python - 将变量写入文本文件并加密?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31161232/