def __init__(self, filename, log=None): """ initialise dictionary of valid properties and list of all file entries """ self.log = log try: pFile = open(filename, "r") except: self.report("error opening " + filename, "e") raise self.properties = {} self.allEntries = pFile.readlines() pFile.close() ep = EncryptedPassword() for entry in self.allEntries: if entry.strip().startswith("#"): # comment line pass elif entry.strip() == "": # blank line pass else: pos = entry.find("=") if pos < 0: key = entry.strip() value = "" else: key = entry[:pos] if key.find("password") > 0: try: value = ep.decrypt(entry[pos + 1:].rstrip()) except: value = entry[pos + 1:].rstrip() else: value = entry[pos + 1:].rstrip() self.properties[key] = value
def __init__(self, fileName): ep = EncryptedPassword() self.rep = SimpleReporter() self.fileName = fileName try: inf = open(fileName, "r") except: self.rep.report("problem opening %s" % (fileName), "e") self.origProps = inf.readlines() inf.close() newLines = [] dirtyFile = 0 for line in self.origProps: if line.strip().startswith("#"): newLines.append(line) continue lineBits = line.split("=") if len(lineBits) < 2: newLines.append(line) continue if not lineBits[0].find("password") > -1: newLines.append(line) continue key = lineBits[0] origVal = "=".join(lineBits[1:]).rstrip() try: ep.decrypt(origVal) newLines.append(line) except: newVal = ep.encrypt(origVal) newLines.append(key + "=" + newVal + "\n") dirtyFile = 1 if dirtyFile: outf = open(fileName, "w") outf.writelines(newLines) outf.close()
import os, sys from crypto import EncryptedPassword from crypto import MaskingPassword MaskingThread = MaskingPassword("-") MaskingThread.start() input = raw_input("Enter the password: "******"[INFO] original password is : %s" % (password) ep = EncryptedPassword() encrypted = ep.encrypt(password) print "[INFO] encrypted password is : %s" % (encrypted) decrypted = ep.decrypt(encrypted) print "[INFO] when \t\t\t %s\nis decrypted we get\t\t %s\nwhich ought to be the same as\t %s" % (encrypted, decrypted, password)
def testRoundTrip(self): print "TestEmbeddedPassword : testRoundTrip" ep = EncryptedPassword() self.assertEqual(ep.decrypt(ep.encrypt("Password123")), "Password123")
def testDecrypt(self): print "TestEmbeddedPassword : testDecrypt" ep = EncryptedPassword() self.assertEqual("password", ep.decrypt("r5ISHXLXSgbYhhLqhtj+Mg=="))
import os, sys from crypto import EncryptedPassword from crypto import MaskingPassword while true: MaskingThread = MaskingPassword("-") MaskingThread.start() input1 = raw_input("Enter the password: "******"Confirm password: "******"[WARN] confirmation does not match the original password" password = input1.strip() ep = EncryptedPassword() try: decrypted = ep.decrypt(input1) print "[INFO] decrypted password is : %s" % (decrypted) except: print "[ERROR] cannot decrypt password %s" % (input1)