我真的很困惑如何在pycrypto中使用计数器模式进行AES解密。据我所知,如果我从一个已知的IV开始解密第一个块,那么对于每个连续的块,我必须增加IV。但我不知道如何做到这一点。
此外,我对python完全陌生,正如你很容易看到的那样。我的问题在于如何实现我的类以及如何从解密器调用它。
以下是我迄今为止编写的代码:
class IVCounter(object):
def incrIV(self):
return self[:15] + chr(ord(self[15:]) + 1)
def decryptCTR(key, ciphertext):
#convert the key into a 16 byte string
key = array.array('B', key.decode("hex")).tostring()
#convert the iv into a 16 byte string
iv = array.array('B', iv.decode("hex")).tostring()
print AES.new(key, mode, counter=IVCounter.incrIV(iv)).decrypt(ciphertext)
return
以下是我得到的错误:
TypeError:必须以IVCounter实例作为第一个参数调用未绑定的方法incrIV()(改为获取str实例)
无论我怎么努力,我都无法让它发挥作用。有人能帮我整理一下吗?
谢谢