My project is to develop a Python application that allows users to encrypt their client-side data and store it securely on my university's NextCloud collaboration system via WebDAV.
I have a problem in the decryption part, I want the file to be downloaded from the cloud but when I enter the name of the file for it to search and download, it doesn't find that file on the cloud, so I have to do this step manually every time, I enter the NextCloud I download the file to my desktop then decrypt it.
What can I do so that the file to be decrypted can be downloaded from the cloud automatically, just by entering the name of the file through my graphical interface?
# Function for selecting a file to decrypt from the cloud
def select_decryption_file():
# Request user credentials to access the cloud
username = simpledialog.askstring("Authentification", "User Name :", parent=window)
password = simpledialog.askstring("Authentification", "Pass Word :", parent=window, show='*')
# Check user identification details
if username == "****" and password == "*****":
file_list = client.list()
if file_list:
selected_file = simpledialog.askstring("Select a file to decrypt", "File name :", parent=window)
found_file = False
for file_info in file_list:
file_name = file_info['path'].split('/')[-1]
if file_name == selected_file:
found_file = True
break
if found_file:
local_file_path = os.path.join(tempfile.gettempdir(), selected_file)
client.download_sync(remote_path=selected_file, local_path=local_file_path)
encryption_key = get_key(selected_file)
if encryption_key:
decrypt_file(local_file_path, encryption_key)
else:
messagebox.showerror("Encryption key not found", "No encryption key is associated with this file.")
os.remove(local_file_path) # Delete the downloaded file after decryption
else:
messagebox.showerror("File not found", "The selected file does not exist on the cloud.")
else:
messagebox.showinfo("No file", "There are no files on the cloud.")
else:
messagebox.showerror("Authentication error", "Incorrect user name or password.")