I have the following script in Python 3.8 (32 bit):
import sys
import time
from Crypto.Cipher import AES
which_file = str(sys.argv[1])
if which_file == "license_service":
nameoffiles = "C:\\file1.txt"
else:
nameoffiles = "C:\\file2.txt"
file_names = open(nameoffiles, "r")
filenames = file_names.read()
filenames1 = filenames.split(',')
key_location = "path_to_key"
key_to_encrypt = open(key_location, "rb")
key = key_to_encrypt.read()
key_to_encrypt.close()
for x in filenames1:
file_in = open(x, "rb")
nonce, tag, ciphertext = [file_in.read(x) for x in (16, 16, -1)]
cipher = AES.new(key, AES.MODE_EAX, nonce)
data = cipher.decrypt_and_verify(ciphertext, tag)
file_in.close()
file_out = open(x, "wb")
file_out.write(data)
This script reads a file containing paths to files that need to be decrypted, then decrypted the files.
The problem is that in one computer (physical machine) it works perfect, never fails, and in another computer (a virtual machine) outputs the following error:
Traceback (most recent call last): File "C:\github\encrypt2\decrypt.py", line 26, in file_out = open(x, "wb") TypeError: coercing to Unicode: need string or buffer, int found
Since the code works OK in one computer, I don't know what can I do to solve this, except to try to find difference between computers configurations.
Couldn't find any difference.