需要帮助来识别错误:+不支持的操作数类型:'_hashlib.HASH'和'bytes'

问题描述

下面是我的代码的一部分

import hashlib
from Crypto.Cipher import AES
from Crypto import Random

...

  def pad(s):
        # Add \x00 (byte) to the end of s to make the len is multiply of AES.block_size
        return s + b"\0"*(AES.block_size - len(s) % AES.block_size)


  def encrypt(key,plaintext):
        # padding original text
        padtext = pad(plaintext)
        
        # Choose a random,AES.block_size.
        iv = Random.new().read(AES.block_size)

        # Create AES-CBC cipher based on key and iv
        cipher = AES.new(key,AES.MODE_CBC,iv)
        
        # Encrypt pad text
        en_cipher = cipher.encrypt(padtext)
        
        # Create checksum
        cs = hashlib.md5(en_cipher).digest()

        return cs + iv + en_cipher

它在我的笔记本电脑上运行,但是当我在另一台PC上运行时,出现此错误

return cs + iv + en_cipher
TypeError: unsupported operand type(s) for +: '_hashlib.HASH' and 'bytes'

我想我想念一个软件包,但是我不确定它是什么。我在任何地方都找不到此错误

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)