def updateFile(self, filepath, contents, organisation, password): # self function can be used when the user chooses to save their work # get the key for the provided organisation key = self.getOrganisationKey(organisation, password) enc = Encrypt(key) encrypted_file = open(filepath, 'wb') encrypted_contents = enc.encrypt_string(contents) encrypted_file.write(encrypted_contents) encrypted_file.close()
def importFile(self, filepath, organisation, password, savepath=None): # first check if the organisation is is a new one if self.isNewOrganisation(organisation): self.createOrganisation(organisation, password) # read the file they provided, encrypt the contents and save it original_file = open(filepath, 'r') original_contents = original_file.read() original_file.close() # load the key for the organisation key = self.getOrganisationKey(organisation, password) enc = Encrypt(key) encrypted_contents = enc.encrypt_string(original_contents) savepath = savepath + '.enc' if savepath == None else savepath encrypted_file = open(savepath, 'wb') encrypted_file.write(encrypted_contents) encrypted_file.close()