I have an issue with FileNotFoundError: [Errno 2] No such file or directory: and i think it have to do with my visual studio code as on other PC it works. In debug console it prints the acctual name of the file Maybe you have any clues what could it be?
questionPass = [{'type': 'password','message': 'Enter your password','name': 'password'}]
questionFile = [{'type': 'input','message': 'Please provide file name','name': 'io_file'}]
questionED = [ {'type': 'list','name': 'EncryptionDecryption','message': 'Please select to encrypt or decrypt the chosen file','choices': ['encrypt', 'decrypt']}]
password_provided = prompt(questionPass)
password = json.dumps(password_provided).encode('UTF-8') # Convert to type bytes
password_decoded = password.decode()
password = json.loads(password_decoded)['password'].encode()
salt = b'salt_'
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
salt=salt,
iterations=100000,
backend=default_backend())
key = base64.urlsafe_b64encode(kdf.derive(password))
iof = prompt(questionFile)
io_file1 = json.dumps(iof)
io_file = json.loads(io_file1)['io_file']
ch = prompt(questionED)
cho = json.dumps(ch)
choice = json.loads(cho)['EncryptionDecryption']
#encryption part
if choice=='encrypt':
with open(io_file, 'rb') as f:
data = f.read()
fernet = Fernet(key)
encrypted = fernet.encrypt(data)
with open(io_file, 'wb') as f:
f.write(encrypted)
print ("\nEncryption part was done successfully")
time.sleep(3)
#decryption part
elif choice=='decrypt':
try:
with open(io_file, 'rb') as f:
data = f.read()
fernet = Fernet(key)
decrypted = fernet.decrypt(data)
with open(io_file, 'wb') as f:
f.write(decrypted)
print ("\nDecryption part was done successfully")
time.sleep(3)
except:
print("Something went wrong. Please restart program and try again!")
time.sleep(3)