예제 #1
0
def reset_all_encrypted_files_with_new_password(old_password, new_password, encryption_strength):
    old_password_hashed = hashlib.sha256(old_password).hexdigest()
    new_password_hashed = hashlib.sha256(new_password).hexdigest()

    file_names = os.listdir(do_not_copy_path)
    file_names.remove(password_file_name)

    from modules.simplecrypt import encrypt, decrypt

    for file_name in file_names:
        path = do_not_copy_path + "/" + file_name
        encrypted_file = open(path, "r")
        encrypted_string = encrypted_file.read()
        encrypted_file.close()
        try:
            decrypted_string = decrypt(old_password_hashed, encrypted_string)
            re_encrypted_string = encrypt(new_password_hashed, decrypted_string)
            with open(path, "w") as output:
                output.write(re_encrypted_string)
            print line_number(), file_name, "has been encrypted and saved"
        except Exception as e:
            print e
            print line_number(), "Error:", file_name, "did not save properly, and the data will need to be retrieved manually with your old password."
    config.PASSWORD = new_password_hashed

    if encryption_strength:
        config.ENCRYPTION_HARDNESS_LEVEL = encryption_strength
        save_encryption_strength(encryption_strength)

    save_password(new_password)
    print line_number(), "You have successfully changed your password."
예제 #2
0
def reset_all_encrypted_files_with_new_password(old_password, new_password,
                                                encryption_strength):
    old_password_hashed = hashlib.sha256(old_password).hexdigest()
    new_password_hashed = hashlib.sha256(new_password).hexdigest()

    file_names = os.listdir(do_not_copy_path)
    file_names.remove(password_file_name)

    from modules.simplecrypt import encrypt, decrypt
    for file_name in file_names:
        path = do_not_copy_path + "/" + file_name
        encrypted_file = open(path, 'r')
        encrypted_string = encrypted_file.read()
        encrypted_file.close()
        try:
            decrypted_string = decrypt(old_password_hashed, encrypted_string)
            re_encrypted_string = encrypt(new_password_hashed,
                                          decrypted_string)
            with open(path, 'w') as output:
                output.write(re_encrypted_string)
            logging.info("{} has been encrypted and saved".format(file_name))
        except Exception as e:
            logging.error(e)
            logging.error(
                "Error: {} did not save properly, and the data will need to be retrieved manually with your old password."
                .format(file_name))
    config.PASSWORD = new_password_hashed

    if encryption_strength:
        config.ENCRYPTION_HARDNESS_LEVEL = encryption_strength
        save_encryption_strength(encryption_strength)

    save_password(new_password)
    logging.info("You have successfully changed your password.")
예제 #3
0
def decrypt_if_possible(path):
    error = False
    #print line_number(), "config.ENCRYPTION_POSSIBLE", config.ENCRYPTION_POSSIBLE
    if config.ENCRYPTION_POSSIBLE:
        try:
            import Crypto
            from modules.simplecrypt import encrypt, decrypt
        except:
            config.ENCRYPTION_POSSIBLE = False
            print line_number(), "Error: DATA_ABOUT_PORTFOLIOS did not load"
            return
        try:
            encrypted_file = open(path, 'r')
            encrypted_string = encrypted_file.read()
            encrypted_file.close()
            pickled_string = decrypt(config.PASSWORD, encrypted_string)
            data = pickle.loads(pickled_string)
        except Exception as e:
            #print line_number(), e
            #print line_number(), "Decryption not possible, account file doesn't exist"
            try:
                unencrypted_pickle_file = open(path.replace(".txt", ".pk"),
                                               'r')
                data = pickle.load(unencrypted_pickle_file)
                unencrypted_pickle_file.close()
                print line_number(
                ), "Decryption not possible, but unencrypted file exists and will be used instead."
            except Exception as e:
                #print line_number(), e
                error = True
    else:
        try:
            unencrypted_pickle_file = open(path.replace(".txt", ".pk"), 'r')
            data = pickle.load(unencrypted_pickle_file)
            unencrypted_pickle_file.close()
        except Exception as e:
            print e
            error = True
    if not error:
        return data
    else:
        if config.ENCRYPTION_POSSIBLE:
            #print line_number(), "Error loading encrypted file"
            #print line_number(), path
            pass
        else:
            #print line_number(), "Error loading unencrypted file"
            #print line_number(), path
            pass
        return None
예제 #4
0
def decrypt_file():
	a = open(test_path, 'r')
	a = a.read()

	b = decrypt(password, a)

	print b

	c = pickle.loads(b)

	print type(c)

	print c.b

#print "end"
예제 #5
0
def decrypt_if_possible(path):
    error = False
    # print line_number(), "config.ENCRYPTION_POSSIBLE", config.ENCRYPTION_POSSIBLE
    if config.ENCRYPTION_POSSIBLE:
        try:
            import Crypto
            from modules.simplecrypt import encrypt, decrypt
        except:
            config.ENCRYPTION_POSSIBLE = False
            print line_number(), "Error: DATA_ABOUT_PORTFOLIOS did not load"
            return
        try:
            encrypted_file = open(path, "r")
            encrypted_string = encrypted_file.read()
            encrypted_file.close()
            pickled_string = decrypt(config.PASSWORD, encrypted_string)
            data = pickle.loads(pickled_string)
        except Exception as e:
            # print line_number(), e
            # print line_number(), "Decryption not possible, account file doesn't exist"
            try:
                unencrypted_pickle_file = open(path.replace(".txt", ".pk"), "r")
                data = pickle.load(unencrypted_pickle_file)
                unencrypted_pickle_file.close()
                print line_number(), "Decryption not possible, but unencrypted file exists and will be used instead."
            except Exception as e:
                # print line_number(), e
                error = True
    else:
        try:
            unencrypted_pickle_file = open(path.replace(".txt", ".pk"), "r")
            data = pickle.load(unencrypted_pickle_file)
            unencrypted_pickle_file.close()
        except Exception as e:
            print e
            error = True
    if not error:
        return data
    else:
        if config.ENCRYPTION_POSSIBLE:
            # print line_number(), "Error loading encrypted file"
            # print line_number(), path
            pass
        else:
            # print line_number(), "Error loading unencrypted file"
            # print line_number(), path
            pass
        return None
def decrypt_if_possible(path, password=""):
	error = False
	print line_number(), "config.ENCRYPTION_POSSIBLE", config.ENCRYPTION_POSSIBLE
	if config.ENCRYPTION_POSSIBLE:
		try:
			import Crypto
			from modules.simplecrypt import encrypt, decrypt
		except:
			config.ENCRYPTION_POSSIBLE = False
			print line_number(), "Error: DATA_ABOUT_PORTFOLIOS did not load"
			return
		try:
			encrypted_file = open(path, 'r')
		except Exception as e:
			print line_number(), e
			print line_number(), "Decryption not possible, account file doesn't exist"
			error = True
		encrypted_string = encrypted_file.read()
		ercrypted_file.close()
		pickled_string = decrypt(password, encrypted_string)
		data = pickle.loads(pickled_string)
	else:
		try:
			unencrypted_pickle_file = open(path, 'r')
			data = pickle.load(unencrypted_pickle_file)
			unencrypted_pickle_file.close()
		except Exception as e:
			print e
			error = True
	if not error:
		return data
	else:
		if config.ENCRYPTION_POSSIBLE:
			print line_number(), "Error loading encrypted file"
			print line_number(), path
		else:
			print line_number(), "Error loading unencrypted file"
			print line_number(), path
		return None