I am trying to create a python script in which you run through all the files in the directory and encrypt them as an alternative to BitLocker. One of the files is just an example passkey as a proof of concept.
I got so far as to get the passkey(s) as input from the user. I downloaded, and imported cryptography.fernet, and created a list of the files in the directory.
I also generated the key that I will use for encryption but am unsure of how to do file encryption with Fernet.
#Script is named match_key.py
from cryptography.fernet import Fernet
import os
#Initialize variables; Specifically the passkey variables
passkey = input("Enter your key: ")
add_key = input("Do you want to enter another key? (y/N) ")
key_list = []
key_list.append(passkey)
encr_file_list = []
#Checks if the user wants to input another key
while add_key == "y" or add_key == "Y":
key = input("Enter your key: ")
key_list.append(passkey)
add_key = input("Do you want to enter another key? (y/N) ")
if add_key == "n" or add_key == "N":
#Store the passwords in a file written to the disk
with open("passwords.txt", "wb") as passwords:
passwords.write(key_list)
break
else:
pass
print(key_list)
#Add each file of the directory to a list except for match_key.py and the encryption key
key = Fernet.generate_key()
for file in os.listdir():
if file == "match_key.py":
continue
if os.path.isfile(file):
encr_file_list.append(file)
print(encr_file_list)
My main question is:
How would I take each file, besides match_key.py and the key, in the directory and encrypt it? Would this be (preferably) possible with a for loop?