python-3.x 我正在创建图像加密和解密使用AES算法

z2acfund  于 2023-05-08  发布在  Python
关注(0)|答案(1)|浏览(150)

当我输入密码加密一些图像错误出现。类型错误:字符串必须在哈希error之前进行编码

def pass_alert():
   messagebox.showinfo("Password Alert","Please enter a password.")

def enc_success(imagename):
   messagebox.showinfo("Success","Encrypted Image: " + imagename)

# image encrypt button event
def image_open():
    global file_path_e

    enc_pass = passg.get()
    if enc_pass == "":
        pass_alert()
    else:
        password = hashlib.sha256(enc_pass).digest()
        filename = filedialog.askopenfilename()
        file_path_e = os.path.dirname(filename)
        encrypt(filename,password)
zfycwa2u

zfycwa2u1#

答:有两种选择。
选择1:
更改此:

password = hashlib.sha256(enc_pass).digest()

致:

password = hashlib.sha256(enc_pass.encode('utf-8')).hexdigest()

备选案文2:

sha256_hash = hashlib.sha256()
message= enc_pass
sha256_hash.update(message.encode())
sha256_hash.hexdigest()

相关问题