使用256的块大小时,Python AES CBC错误具有字符串大小

时间:2018-07-01 06:34:49

标签: python encryption aes

此刻,我正在尝试各种加密,但遇到一个我无法解决的问题。我正在尝试在bbc模式下使用pycrypto.cipher的AES实现,其块大小为256。直到128的所有块大小都可以正常工作,但以上情况给了我以下错误:

"{"things":[{"ID":1,"PRICE":1.23,"PRICE2":2.34,"PRICE3":3.45,"PRICE4":5.67},{"ID":2,"PRICE":4.53,"PRICE2":6.34,"PRICE3":6.45,"PRICE4":7.67},{"ID":3,"PRICE":100,"PRICE2":0,"PRICE3":0,"PRICE4":0},{"ID":4,"PRICE":200,"PRICE2":3434,"PRICE3":0,"PRICE4":0},{"ID":5,"PRICE":11,"PRICE2":0,"PRICE3":2,"PRICE4":33},{"ID":6,"PRICE":3,"PRICE2":0,"PRICE3":0,"PRICE4":0},{"ID":7,"PRICE":4,"PRICE2":33,"PRICE3":0,"PRICE4":0},{"ID":8,"PRICE":1,"PRICE2":0,"PRICE3":0,"PRICE4":0},{"ID":9,"PRICE":100,"PRICE2":118,"PRICE3":3,"PRICE4":4}]}"

前两个数字(32和1536)显示了密钥(32)的长度和填充的消息的长度,都可以被16整除。

这是我使用的代码,randomstring函数和secrets库仅用于获取随机数据,使用手工数据不会更改结果。

32
1536
Traceback (most recent call last):
  File "ttt.py", line 38, in <module>
    crypter.encryptB64('hallo123', randomstring(size=1024))
  File "ttt.py", line 28, in encryptB64
    return base64.b64encode(self.encrypt(key.encode(), value)).decode()
  File "ttt.py", line 19, in encrypt
    crypted = cipher.encrypt(self.pkcs5_pad(value))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pycrypto-2.6.1-py3.6-macosx-10.6-intel.egg/Crypto/Cipher/blocka
lgo.py", line 244, in encrypt
    return self._cipher.encrypt(plaintext)
ValueError: Input strings must be a multiple of 16 in length

1 个答案:

答案 0 :(得分:0)

根据定义,

AES的块大小为128位。不多不少。如果块大小为256位,则不是AES,而是Rijndael。