pycryptodome:OverFlayRor:柜台已在CTR模式下包裹



我在python上使用pycryptodome使用AES-CTR加密很难。我不明白这个错误的含义或如何解决。

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

我弄清楚了。NONCE只有1个字节较短,因此计数器模式只能产生256个块,这将允许加密4096字节。如果nonce很少,问题就会消失。

最新更新