1

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.

3
  • What are the operating systems/python versions? Commented Mar 15, 2020 at 15:58
  • python 38 32 bit, the physical is windows 10 2017 enterprise, the VM is windows 10 pro 2019 Commented Mar 15, 2020 at 16:00
  • print x before file_out=open(..) and see why it is something an int on not a string Commented Mar 15, 2020 at 16:06

1 Answer 1

1

Solved, the vm has also installed python 2.7, after uninstalling and set var path to 3.8 everything worked well

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.