I'm creating image encryption and decryption using AES algorithm

184 Views Asked by At

When I enter a password to encrypt some image error appear. Type error: String must be encoded before hashing 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)

1

There are 1 best solutions below

2
toyota Supra On

Edit: There are two options.

Option 1:

Change this:

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

to:

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

Option 2:.

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