python - 将变量写入文本文件并加密?

标签 python security encryption save python-3.4

我知道如何将用户输入保存到文本文件,但我该如何加密呢?这是我将用户输入保存到文本文件的方法。我尝试了 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

PyCrypto

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/

相关文章:

python - 用 beautifulsoup 克隆元素

python - 当数据库值更改时,Django 发送推送通知

security - 在 sitecore 中的主页项上设置字段级安全性

java - 加密和解密应用程序 key

c# - 无法从 VB.Net 验证 C++ 中的签名哈希

python - 如何在 python 中递归创建排列列表?

Python:为什么数据被插入到列表/字典的两个字典中

Spring 安全 : java. lang.ClassNotFoundException : org. springframework.dao.support.DaoSupport

javascript - 我用我的 PHP 调用的数据文件被神秘地改变了。用户是否覆盖了它?

python - 是否需要将文件分成 block 进行加密