我试图得到一个python程序,解密一些Base64 64编码,加密使用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'添加什么,以及如何在这段代码中指定它的位级别?
发布于 2017-06-27 03:35:00
您使用的是AES.MODE_CBC,这意味着输入字符串,即'This is a key123'必须是16个字节的倍数。
如果您想继续使用这种模式,那么您将需要填充您的字符串。这个git回购是在CBC模式下使用填充的AES加密的一个很好的例子。
https://stackoverflow.com/questions/42129616
复制相似问题