python-3.x - 如何使用python加密和解密带有密码的字符串
问题描述
我正在制作一个供个人使用的小型密码管理器。我想知道是否可以使用密码创建加密字符串。此密码将是字符串或字节。我还从密码学中查看了 Fernet 类,但我想成为 abel 记住密码,所以这是没有选择的。我也想解密。
解决方案
查看https://pypi.org/project/pycrypto/
该网站的示例(这似乎是您需要的):
>>> from Crypto.Cipher import AES
>>> obj = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
>>> message = "The answer is no"
>>> ciphertext = obj.encrypt(message)
>>> ciphertext
'\xd6\x83\x8dd!VT\x92\xaa`A\x05\xe0\x9b\x8b\xf1'
>>> obj2 = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
>>> obj2.decrypt(ciphertext)
'The answer is no'
推荐阅读
- telethon - 使用 Telethon 获取特定 ID 后的电报频道消息
- python - python中的地板和天花板函数
- php - 显示一些数据和一个详细信息按钮以显示详细信息
- java - 使用手机查询数据时数据丢失
- html - 仅在桌面上重新排列引导导航栏中的浮动 li 元素
- angularjs - 手动导航在 AngularJS 1.7 的 ui-router 中不起作用
- mongodb - 至少一个在 mongodb
- jquery - 如果在引导下拉列表中未找到结果,则附加自定义选项(选择选择器)
- java - 将 MadelAndObject 属性传递给子 jsp 页面
- javascript - 由 npx/node/npm 执行的 google 闭包编译器