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 testEncrypt(self): print "TestEmbeddedPassword : testEncrypt" ep = EncryptedPassword() self.assertEqual("r5ISHXLXSgbYhhLqhtj+Mg==", ep.encrypt("password"))
def testRoundTrip(self): print "TestEmbeddedPassword : testRoundTrip" ep = EncryptedPassword() self.assertEqual(ep.decrypt(ep.encrypt("Password123")), "Password123")