我在 Python 3 上使用 pycryptodome 进行 AES-CTR 加密时遇到了困难。数据可能约为 1000 字节,但当它变得足够长时它会中断。我不明白这个错误应该是什么意思或如何解决它。
from os import urandom
from Crypto.Cipher import AES
cipher = AES.new(urandom(16), AES.MODE_CTR, nonce=urandom(15))
cipher.encrypt(urandom(10000))
---------------------------------------------------------------------------
OverflowError Traceback (most recent call last)
<ipython-input-116-a48990362615> in <module>()
3
4 cipher = AES.new(urandom(16), AES.MODE_CTR, nonce=urandom(15))
----> 5 cipher.encrypt(urandom(10000))
6
/usr/local/lib/python3.5/dist-packages/Crypto/Cipher/_mode_ctr.py in encrypt(self, plaintext)
188 if result:
189 if result == 0x60002:
--> 190 raise OverflowError("The counter has wrapped around in"
191 " CTR mode")
192 raise ValueError("Error %X while encrypting in CTR mode" % result)
OverflowError: The counter has wrapped around in CTR mode