def GetPassFromFile(index, encryptionKey): AESEncryptionKey = Encryptor.BindKey(Encryptor.GetKey(), encryptionKey) if (not DoesProgramFileExist(passFile)): return None with open((GetFileLocation() + passFile), "r") as f: dataSet = f.readline() #Decrypt file data = Encryptor.DecryptFile(dataSet, AESEncryptionKey) sepData = SplitString(data[index], sep2) foundPass = Encryptor.AESDecrypt(sepData[2], AESEncryptionKey) splitData = foundPass.split(userpassSep) toReturn = [] if (splitData[1].lower() != "null"): toReturn.append("USER: "******"PASS: "******"null"): toReturn.append("Additional: " + splitData[2]) #Add group to return if (sepData[0].lower() != "null"): toReturn.append("") toReturn.append("In group: " + sepData[0]) return toReturn
def RenamePassTitle(newPassTitle, lineNum, encryptionKey): AESEncryptionKey = Encryptor.BindKey(Encryptor.GetKey(), encryptionKey) if (not DoesProgramFileExist(passFile)): return False #Get Current File with open((GetFileLocation() + passFile), "r") as f: data = f.readline() fileContent = Encryptor.DecryptFile(data, AESEncryptionKey) if (lineNum < 0 or lineNum >= len(fileContent)): return False #Get password locker line fullLine = SplitString(fileContent[lineNum], sep2) lineToWrite = fullLine[0] + sep2 + Encryptor.AESEncrypt( newPassTitle, AESEncryptionKey) + sep2 + fullLine[2] #Write back to file fileContent[lineNum] = lineToWrite writeFileString = Encryptor.EncryptFile(fileContent, AESEncryptionKey) with open((GetFileLocation() + passFile), "w") as f: f.write(writeFileString) return True
def GetPasswordGroups(encryptionKey): AESEncryptionKey = Encryptor.BindKey(Encryptor.GetKey(), encryptionKey) if (not DoesProgramFileExist(passFile)): return None with open((GetFileLocation() + passFile), "r") as f: dataSet = f.readline() #Decrypt file data = Encryptor.DecryptFile(dataSet, AESEncryptionKey) groups = [] for i in range(0, len(data)): foundGroup = SplitString(data[i], sep2)[0] if (foundGroup[0] != "#" and foundGroup.lower() != "null"): groups.append(foundGroup) return groups
def GetPasswordTitle(searchTerm, encryptionKey): AESEncryptionKey = Encryptor.BindKey(Encryptor.GetKey(), encryptionKey) if (not DoesProgramFileExist(passFile)): return None with open((GetFileLocation() + passFile), "r") as f: encDataSet = f.readline() dataSet = Encryptor.DecryptFile(encDataSet, AESEncryptionKey) for idx, data in enumerate(dataSet): if (data != "" and data[0] != "#"): title = SplitString(data, sep2)[1] foundTitle = Encryptor.AESDecrypt(title, AESEncryptionKey).lower() if (searchTerm.lower() == foundTitle): return idx return -1
def DeletePassword(passIndex, encryptionKey): AESEncryptionKey = Encryptor.BindKey(Encryptor.GetKey(), encryptionKey) #Read all from file if (not DoesProgramFileExist(passFile)): return None with open((GetFileLocation() + passFile), "r") as f: encDataSet = f.readline() data = Encryptor.DecryptFile(encDataSet, AESEncryptionKey) #Remove unwanted password del data[passIndex] try: #Re-write file encDataSet = Encryptor.EncryptFile(data, AESEncryptionKey) with open((GetFileLocation() + passFile), "w") as f: f.write(encDataSet) return True except: return False
def GetPasswordTitles(encryptionKey, byGroup="NULL"): AESEncryptionKey = Encryptor.BindKey(Encryptor.GetKey(), encryptionKey) if (not DoesProgramFileExist(passFile)): return None with open((GetFileLocation() + passFile), "r") as f: encDataSet = f.readline() titles = [] dataSet = Encryptor.DecryptFile(encDataSet, AESEncryptionKey) for data in dataSet: if (data != "" and data[0] != "#"): splitData = SplitString(data, sep2) title = splitData[1] if (byGroup != "NULL"): if (splitData[0].lower() == byGroup.lower()): titles.append(Encryptor.AESDecrypt(title, AESEncryptionKey)) else: titles.append(Encryptor.AESDecrypt(title, AESEncryptionKey)) return titles
def AmmendPasswordFile(passTitle, password, encryptionKey, inputUsername="******", inputExtra="null", inputGroup="null", lineNum=-1): AESEncryptionKey = Encryptor.BindKey(Encryptor.GetKey(), encryptionKey) #Returns successful runs, if (not DoesProgramFileExist(passFile)): #Will create the file if it doesn't exist toWrite = ["#Locker.psl"] encryptedLineWrite = Encryptor.EncryptFile(toWrite, AESEncryptionKey) with open((GetFileLocation() + passFile), "w+") as pF: pF.write(encryptedLineWrite) #Get Current File with open((GetFileLocation() + passFile), "r") as f: data = f.readline() fileContent = Encryptor.DecryptFile(data, AESEncryptionKey) #lineNum = -1 denotes a new password to be added if (lineNum >= 0 and lineNum < len(fileContent) and (password == "" or inputUsername == "" or inputGroup == "" or inputExtra == "")): #Check what values = '' and overrite with stored data #First seperate fileContent by sep2 sep2Content = SplitString(fileContent[lineNum], sep2) #Now update group values if (inputGroup == ""): inputGroup = sep2Content[0] #Now get user/pass segment userPassSeg = Encryptor.AESDecrypt(sep2Content[2], AESEncryptionKey).split(userpassSep) if (password == ""): password = userPassSeg[0] if (inputUsername == ""): inputUsername = userPassSeg[1] if (inputExtra == ""): inputExtra = userPassSeg[2] print(inputExtra) lineWrite = inputGroup + sep2 + Encryptor.AESEncrypt( passTitle, AESEncryptionKey) + sep2 + Encryptor.AESEncrypt( password + userpassSep + inputUsername + userpassSep + inputExtra, AESEncryptionKey) #Ammend file contents if (lineNum == -1): fileContent.append(lineWrite) elif (lineNum >= 0): if (lineNum > len(fileContent)): return False fileContent[lineNum] = lineWrite else: raise ValueError("Invalid edit number, use '-1' to add new password") #Write back to file writeFileString = Encryptor.EncryptFile(fileContent, AESEncryptionKey) with open((GetFileLocation() + passFile), "w") as f: f.write(writeFileString) return True