【问题标题】:Crypto.Cipher AES.MODE_EAX encrypt_and_digest error: argument 2 must be bytes, not bytearrayCrypto.Cipher AES.MODE_EAX encrypt_and_digest 错误:参数 2 必须是字节,而不是字节数组
【发布时间】:2019-07-07 15:53:27
【问题描述】:

以下代码给了我错误“参数 2 必须是字节,而不是字节数组”。我找不到任何关于 encrypt_and_digest 的文档,除了一些示例代码,它们都只是将一个参数传递给该方法。有人知道这里有什么问题吗?谢谢。

key = rb(16)
cipher = AES.new(key, AES.MODE_EAX)
ciphertext, tag = cipher.encrypt_and_digest(b'hello')

【问题讨论】:

    标签: aes pycrypto


    【解决方案1】:

    很可能您已经安装了 pycryptodome 和旧的 pycrypto 软件包。

    运行“pip uninstall pycrypto”并重试。

    更多详情见 https://pycryptodome.readthedocs.io/en/latest/src/faq.html

    【讨论】:

      【解决方案2】:

      我将错误源追溯到下面代码的第三行

      partial = self._cache[:]
      partial[self._cache_n:] = b'\x80' + b'\x00' * (bs - self._cache_n - 1)
      pt = strxor(strxor(self._last_ct, partial), self._k2)
      

      在文件python3.7/site-packages/Crypto/Hash/CMAC.py的函数摘要中。 错误与第二个参数部分有关,它是一个字节数组。当我将第三行修改为以下内容时,错误消失了。

      pt = strxor(strxor(self._last_ct, bytes(partial)), self._k2)
      

      【讨论】:

        猜你喜欢
        • 2020-03-29
        • 2017-06-07
        • 2016-11-26
        • 2020-12-03
        • 2018-04-12
        • 2018-09-13
        • 1970-01-01
        • 2019-09-16
        • 1970-01-01
        相关资源
        最近更新 更多