首页 > 解决方案 > 如何使用python加密和解密带有密码的字符串

问题描述

我正在制作一个供个人使用的小型密码管理器。我想知道是否可以使用密码创建加密字符串。此密码将是字符串或字节。我还从密码学中查看了 Fernet 类,但我想成为 abel 记住密码,所以这是没有选择的。我也想解密。

标签: python-3.xencryption

解决方案


查看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'


推荐阅读