【发布时间】:2017-02-09 06:22:58
【问题描述】:
我正在尝试获取一个 python 程序,它可以解密一些 Base64 编码、在 ECB 模式下使用 AES-128 加密的文本。
所以,我正在使用本教程:http://docs.python-guide.org/en/latest/scenarios/crypto/ 开始。
它包含以下代码:
from Crypto.Cipher import AES
# Encryption
encryption_suite = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
cipher_text = encryption_suite.encrypt("A really secret message. Not for prying eyes.")
# Decryption
decryption_suite = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
plain_text = decryption_suite.decrypt(cipher_text)
我已将代码复制到 aes_2.py 文件中。而且,我使用以下方式运行它:sudo python3 aes_2.py
我明白了:
Traceback (most recent call last):
File "aes_2.py", line 21, in <module>
cipher_text = encryption_suite.encrypt("A really secret message. Not for prying eyes.")
File "/usr/local/lib/python3.5/dist-packages/Crypto/Cipher/blockalgo.py", line 244, in encrypt
return self._cipher.encrypt(plaintext)
ValueError: Input strings must be a multiple of 16 in length
编辑 1
我有一个文件,我被告知要解密。我得到了一个密钥和文件以及一些关于解密的规范。这个站点解密它:http://aesencryption.net/ 当我输入密钥、128 位和文本进入站点时。
对于上面的这段代码。我有几个问题。我应该为'This is an IV456' 输入什么以及如何在此代码中指定它的位级别?
【问题讨论】:
-
@Arman 你是对的,我添加了几个字符然后它运行了。奇怪,我根本没有改变教程。
标签: python encryption