Implemented decryption of user file

This commit is contained in:
Kevin Veen-Birkenbach 2022-12-09 20:39:00 +01:00
parent 10689122c0
commit b3c31c0013
3 changed files with 12 additions and 9 deletions

View File

@ -17,8 +17,8 @@ class AbstractSplittedSecret(Cli):
def getFileExtension(self,file_type): def getFileExtension(self,file_type):
if file_type == "encrypted": if file_type == "encrypted":
return '' return '.gpg'
return '.gpg' return ''
def getUserFilePath(self,user_id,file_type): def getUserFilePath(self,user_id,file_type):
return self.getUserFilesFolderPath(file_type)+user_id+'.json' + self.getFileExtension(file_type); return self.getUserFilesFolderPath(file_type)+user_id+'.json' + self.getFileExtension(file_type);

View File

@ -4,7 +4,7 @@ class Decryption(AbstractSplittedSecret):
def __init__(self): def __init__(self):
self.user_id='0'; self.user_id='0';
self.user_password='' self.user_password=''
pass super(Decryption, self).__init__()
def setUserId(self,user_id): def setUserId(self,user_id):
self.user_id=str(user_id) self.user_id=str(user_id)
@ -12,12 +12,13 @@ class Decryption(AbstractSplittedSecret):
def setUserPassword(self,user_password): def setUserPassword(self,user_password):
self.user_password = str(user_password) self.user_password = str(user_password)
def decryptFile(self,password,input_file_path): def decryptFile(self,password,input_file_path,output_file_path):
self.executeCommand('gpg --batch --passphrase "'+ password + '" '+ file_path) self.executeCommand('gpg --batch --passphrase "'+ password + '" -o "' + output_file_path +'" "'+ input_file_path+'"')
print(self.getCommandString()) print(self.getCommandString())
print(self.getOutputString()) print(self.getOutputString())
def decryptUserFile(self): def decryptUserFile(self):
input_file_path = self.getUserFilePath(self.user_id) input_file_path = self.getUserFilePath(self.user_id,"encrypted")
self.decryptFile(self.user_password, file_path) output_file_path = self.getUserFilePath(self.user_id,"decrypted")
self.decryptFile(self.user_password, input_file_path,output_file_path)

View File

@ -25,11 +25,13 @@ if __name__ == '__main__':
decrypt = Decryption() decrypt = Decryption()
if args.user is None: if args.user is None:
print("Please type in the user number:") print("Please type in the user number:")
decrypt.setUser(int(input())) decrypt.setUserId(input())
else: else:
decrypt.setUser(args.user) decrypt.setUser(args.user)
print("Please enter the master password:") print("Please enter the master password:")
user_password = getpass() decrypt.setUserPassword(getpass())
print("Decrypting User File...")
decrypt.decryptUserFile();
exit() exit()