我已经加密了密码,结果是这样的:b'& Ti \ xcfK \ x15 \ xe2 \ x19 \ x0c' 我想将它保存到配置文件并重新加载它 所以我可以解密它,我可以再次使用它作为密码Python写入b'xxxx'配置并读取它
0
A
回答
1
# To save it:
with open('file-to-save-password', 'bw') as f:
f.write(b'&Ti\xcfK\x15\xe2\x19\x0c')
# To read it:
with open('file-to-save-password', 'br') as f:
print(f.read())
0
看看Python的open
内置函数。
with open('foo.txt', 'wb') as f:
f.write(b'&Ti\xcfK\x15\xe2\x19\x0c')
0
你可以做这样的事情:
# to write the file
cryptpw = "your encrypted password"
config = open("/path/to/config/file/pw.config","w")
config.write(cryptpw)
config.close()
# to reopen it
config = open("/path/to/config/file/pw.config","r")
print(config.read())
config.close()
这是给你,你与该文件的内容是什么,我只是选择了将其打印出来。
0
python persistence在这里很有用。例如:
import shelve
with shelve.open('secrets') as db:
db['password'] = b'&Ti\xcfK\x15\xe2\x19\x0c'
相关问题
- 1. 打开cmd并读取和写入它
- 2. Python的读取/写入
- 3. 写入并读取到SDcard
- 4. 并行读取和写入
- 5. 写入并读取Android
- 6. 并行读取/写入ADLA
- 7. Python瓶写入一个CSV文件并阅读它
- 8. Apache Commons配置:读取.properties文件并且不改变地重写它
- 9. 写入和读取应用程序配置设置
- 10. 写入一个文件并从python中的子进程中读取它?
- 11. Python:写入文件并将其读回
- 12. 将多行写入文件,然后用Python读取它们
- 13. 将整数值写入文件并读取它
- 14. Java - Windows 7读取文件并将它们写入列表
- 15. JAVA - 将二进制数写入文件并读取它
- 16. 如何将更多值写入管道并读取它们?
- 17. 读取UTF-8文本行并将它们写入文件
- 18. 从C#读取XML文件中的值并写入它#
- 19. sunspot_rails不会读取它的配置sunspot.yml
- 20. Python:读取和写入CSV文件
- 21. 在Python中读取/写入文件
- 22. python读取/写入文件列表
- 23. Python - 写入和读取临时文件
- 24. Python快速读取和写入文件
- 25. 读取和写入数据包python-scapy
- 26. 在python中分开读取和写入
- 27. 从python中读取和写入文件
- 28. 写入和读取字典Python 3
- 29. Python:读取和写入多个文件
- 30. 从python中读取/写入android文件