From 72765e280d76e467b70a841741b6169504b9b884 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 9 Dec 2022 22:55:33 +0100 Subject: [PATCH] Implemented loading of json file --- scripts/classes/Decryption.py | 17 ++++++++++++++--- scripts/main.py | 6 ++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/classes/Decryption.py b/scripts/classes/Decryption.py index e9b7fec..7fb88c1 100644 --- a/scripts/classes/Decryption.py +++ b/scripts/classes/Decryption.py @@ -1,4 +1,5 @@ from .AbstractSplittedSecret import AbstractSplittedSecret +import json class Decryption(AbstractSplittedSecret): def __init__(self): @@ -8,19 +9,29 @@ class Decryption(AbstractSplittedSecret): def setUserId(self,user_id): self.user_id=str(user_id) + self.user_file_decrypted_path = self.getUserFilePath(self.user_id,"decrypted") def setUserPassword(self,user_password): self.user_password = str(user_password) + def loadJsonFile(self,file_path): + file = open(file_path) + data = json.load(file) + file.close() + return data + def decryptFile(self,password,input_file_path,output_file_path): self.executeCommand('gpg --batch --passphrase "'+ password + '" -o "' + output_file_path +'" "'+ input_file_path+'"') def decryptUserFile(self): input_file_path = self.getUserFilePath(self.user_id,"encrypted") - output_file_path = self.getUserFilePath(self.user_id,"decrypted") - self.decryptFile(self.user_password, input_file_path, output_file_path) + self.decryptFile(self.user_password, input_file_path, self.user_file_decrypted_path) def decryptAccumulatedFile(self): input_file_path = self.getAccumulatedFilePath("encrypted") output_file_path = self.getAccumulatedFilePath("decrypted") - self.decryptFile(self.user_password, input_file_path, output_file_path) \ No newline at end of file + self.decryptFile(self.user_password, input_file_path, output_file_path) + + def setUserData(self): + self.decryptUserFile() + self.user_data = self.loadJsonFile(self.user_file_decrypted_path) \ No newline at end of file diff --git a/scripts/main.py b/scripts/main.py index 1589dbe..2fa67be 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -39,11 +39,13 @@ if __name__ == '__main__': decrypt.setUserPassword(getpass()) print("Decrypting User File...") try: - decrypt.decryptUserFile(); + decrypt.setUserData(); break; except: print("Wrong password :(") - print("File encrypted :) ") + print("File decrypted :) ") + print("Please contact ") + print(decrypt.user_data) exit() print("Decrypting accumulated file...") decrypt.setUserPassword(args.master_password)