figenc

[RADIOACTIVE] rsa and symmetric key encryption scripts and executables
git clone git://git.figbert.com/figenc.git
Log | Files | Refs | README

commit 5d119c960ee0208df79f479db2ad46675dc6c231
parent 78dfa084a1e85b557c3d7aaa2833c4e0fab6af68
Author: therealFIGBERT <naomi@Naomis-MacBook-Air.local>
Date:   Sat, 29 Jun 2019 00:00:33 -0700

Massively upgrading the MacOS GUI and adding encryption functionality

Diffstat:
Mdecrypt.py | 65+++++++++++++++++++++++++++++++++--------------------------------
Mencrypt.py | 61+++++++++++++++++++++++++++++++------------------------------
MfigENC_MacOS.py | 135++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------
Minitiate_key.py | 16+++++++++++-----
4 files changed, 188 insertions(+), 89 deletions(-)

diff --git a/decrypt.py b/decrypt.py @@ -5,35 +5,36 @@ from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import padding from cryptography.fernet import Fernet -def rsa_dec(): - passcode = input("Private Key passcode: ") - with open('private_key.pem', 'rb') as private_key_file: - private_key = serialization.load_pem_private_key( - private_key_file.read(), - password=bytes(passcode, 'utf-8'), - backend=default_backend() - ) - with open('symmetric_key.key', 'rb') as symmetric_key_file: - encoded_key_data = symmetric_key_file.read() - symmetric_key_data = private_key.decrypt( - encoded_key_data, - padding.OAEP( - mgf=padding.MGF1(algorithm=hashes.SHA256()), - algorithm=hashes.SHA256(), - label=None +def rsa_dec(target_file_raw, save_folder, passkey): + passcode = passkey + target_file_list = target_file_raw.split(":") + if save_folder[-1] != '/': + save_folder += '/' + private_key_source = save_folder + 'private_key.pem' + symmetric_key_source = save_folder + 'symmetric_key.key' + for target_file in target_file_list: + with open(private_key_source, 'rb') as private_key_file: + private_key = serialization.load_pem_private_key( + private_key_file.read(), + password=bytes(passcode, 'utf-8'), + backend=default_backend() ) - ) - symmetric_key = Fernet(symmetric_key_data) - file_to_decrypt = input("File to decrypt: ") - with open(file_to_decrypt, 'rb') as read_file: - encrypted_data = read_file.read() - original_message = symmetric_key.decrypt(encrypted_data) - with open(file_to_decrypt, 'wb') as write_file: - write_file.write(original_message) - decrypt_symmetry = input("Are you decrypting more files this session? (y/n): ") - if decrypt_symmetry == "n": - with open('symmetric_key.key', 'wb') as symmetric_file: - symmetric_file.write(symmetric_key_data) - print("Decryption completed.\n") - else: - print("Decryption completed.\n") -\ No newline at end of file + with open(symmetric_key_source, 'rb') as symmetric_key_file: + encoded_key_data = symmetric_key_file.read() + symmetric_key_data = private_key.decrypt( + encoded_key_data, + padding.OAEP( + mgf=padding.MGF1(algorithm=hashes.SHA256()), + algorithm=hashes.SHA256(), + label=None + ) + ) + symmetric_key = Fernet(symmetric_key_data) + file_to_decrypt = target_file + with open(file_to_decrypt, 'rb') as read_file: + encrypted_data = read_file.read() + original_message = symmetric_key.decrypt(encrypted_data) + with open(file_to_decrypt, 'wb') as write_file: + write_file.write(original_message) + with open(symmetric_key_source, 'wb') as symmetric_file: + symmetric_file.write(symmetric_key_data) +\ No newline at end of file diff --git a/encrypt.py b/encrypt.py @@ -5,33 +5,34 @@ from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import padding from cryptography.fernet import Fernet -def rsa_enc(): - with open('public_key.pem', 'rb') as public_key_file: - public_key = serialization.load_pem_public_key( - public_key_file.read(), - backend=default_backend() +def rsa_enc(target_file_raw, save_folder): + target_file_list = target_file_raw.split(":") + if save_folder[-1] != '/': + save_folder += '/' + public_key_source = save_folder + 'public_key.pem' + symmetric_key_source = save_folder + 'symmetric_key.key' + for target_file in target_file_list: + with open(public_key_source, 'rb') as public_key_file: + public_key = serialization.load_pem_public_key( + public_key_file.read(), + backend=default_backend() + ) + with open(symmetric_key_source, 'rb') as symmetric_key_file: + symmetric_key_data = symmetric_key_file.read() + symmetric_key = Fernet(symmetric_key_data) + file_to_encrypt = target_file + with open(file_to_encrypt) as read_file: + file_data = read_file.read() + data = symmetric_key.encrypt(bytes(file_data, 'utf-8')) + encrypted_key = public_key.encrypt( + symmetric_key_data, + padding.OAEP( + mgf=padding.MGF1(algorithm=hashes.SHA256()), + algorithm=hashes.SHA256(), + label=None + ) ) - with open('symmetric_key.key', 'rb') as symmetric_key_file: - symmetric_key_data = symmetric_key_file.read() - symmetric_key = Fernet(symmetric_key_data) - file_to_encrypt = input("File to encrypt: ") - with open(file_to_encrypt) as read_file: - file_data = read_file.read() - data = symmetric_key.encrypt(bytes(file_data, 'utf-8')) - encrypted_key = public_key.encrypt( - symmetric_key_data, - padding.OAEP( - mgf=padding.MGF1(algorithm=hashes.SHA256()), - algorithm=hashes.SHA256(), - label=None - ) - ) - with open(file_to_encrypt, 'wb') as write_file: - write_file.write(data) - encrypt_symmetry = input("Are you encrypting more files this session? (y/n): ") - if encrypt_symmetry == "n": - with open('symmetric_key.key', 'wb') as crypto_key_file: - crypto_key_file.write(encrypted_key) - print("Encryption successful. Proceed into cyberspace with confidence.\n") - else: - print("Encryption successful. Proceed into cyberspace with confidence.\n") -\ No newline at end of file + with open(file_to_encrypt, 'wb') as write_file: + write_file.write(data) + with open(symmetric_key_source, 'wb') as crypto_key_file: + crypto_key_file.write(encrypted_key) +\ No newline at end of file diff --git a/figENC_MacOS.py b/figENC_MacOS.py @@ -2,6 +2,96 @@ from initiate_key import rsa_key from encrypt import rsa_enc from decrypt import rsa_dec import tkinter as tk +from os import makedirs +from os import path as Path + +crypto_mode = "" +def setup(mode): + mode = mode[0] + global crypto_mode + if mode == 0: + passcode_label.pack_forget() + passcode_instructions.pack_forget() + passcode_input.pack_forget() + file_label.config(text="Filepath/s to the file/s to encrypt") + file_label.pack() + file_instructions.pack() + file_input.pack(fill='x') + passcode_label.config(text="Set private key passcode") + passcode_label.pack() + passcode_instructions.config(text="CRITICAL: DO NOT FORGET YOUR PASSCODE.\nWITHOUT IT, YOUR DATA WILL BE LOST.") + passcode_instructions.pack() + passcode_input.pack(fill='x') + save_label.pack() + save_instructions.pack() + save_input.pack(fill="both") + submit.config(text="Encrypt file/s") + submit.pack() + crypto_mode = "key_enc" + elif mode == 1: + file_label.config(text="Filepath/s to the file/s to encrypt") + file_label.pack() + file_instructions.pack() + file_input.pack(fill='x') + passcode_label.pack_forget() + passcode_instructions.pack_forget() + passcode_input.pack_forget() + save_label.config(text="Key location") + save_label.pack() + save_instructions.config(text="Filepath to matching key trio") + save_instructions.pack() + save_input.pack(fill="both") + submit.config(text="Encrypt file/s") + submit.pack() + crypto_mode = "enc" + elif mode == 2: + passcode_label.pack_forget() + passcode_instructions.pack_forget() + passcode_input.pack_forget() + file_label.config(text="Filepath/s to the file/s to decrypt") + file_label.pack() + file_instructions.pack() + file_input.pack(fill='x') + passcode_label.config(text="Private key passcode") + passcode_label.pack() + passcode_instructions.config(text="Passcode must be the same passcode used when the keys were created") + passcode_instructions.pack() + passcode_input.pack(fill='x') + save_label.pack() + save_instructions.pack() + save_input.pack(fill="both") + submit.config(text="Decrypt file/s") + submit.pack() + crypto_mode = "dec" + elif mode == 3: + passcode_label.pack_forget() + passcode_instructions.pack_forget() + passcode_input.pack_forget() + file_label.pack_forget() + file_instructions.pack_forget() + file_input.pack_forget() + passcode_label.config(text="Set private key passcode") + passcode_label.pack() + passcode_instructions.config(text="CRITICAL: DO NOT FORGET YOUR PASSCODE.\nWITHOUT IT, YOUR DATA WILL BE LOST.") + passcode_instructions.pack() + passcode_input.pack(fill='x') + save_label.pack() + save_instructions.pack() + save_input.pack(fill="both") + submit.config(text="Create keys") + submit.pack() + crypto_mode = "just_key" + +def go(mode, save_folder, target_file, passkey=None): + if mode == "key_enc": + rsa_key(passkey, save_folder) + rsa_enc(target_file, save_folder) + elif mode == "enc": + rsa_enc(target_file, save_folder) + elif mode == "dec": + rsa_dec(target_file, save_folder, passkey) + elif mode == "just_key": + rsa_key(passkey, save_folder) root = tk.Tk() root.wm_title("figENC") @@ -10,38 +100,39 @@ canvas.pack() frame = tk.Frame(root, bg='white') frame.place(relwidth=1, relheight=1) -header = tk.Label(frame, text="figENC\nIndustry leading encryption by FIGBERT", bg="gray", fg="black", justify="center", font=("Arial", "18")) +header = tk.Label(frame, text="figENC\nIndustry leading encryption by FIGBERT", bg="gray", fg="black", justify="center", font=("Arial", "24")) header.pack(fill="x", side="top", ipady="5") action = tk.Frame(frame, bg="white") action.pack(fill='both') action_label = tk.Label(action, text="Action:", bg="white", justify='left', font=("Arial", "14")) action_label.pack() -action_list = tk.Listbox(action, bg="white", selectmode="single", font=("Arial", "12"), height=3, bd=1) +action_list = tk.Listbox(action, bg="white", selectmode="single", font=("Arial", "12"), height=4, bd=1) action_list.insert(1, "Encrypt with fresh keys") -action_list.insert(2, "Encrypt with generated key") -action_list.insert(3, "Decrypt with generated key") +action_list.insert(2, "Encrypt with generated keys") +action_list.insert(3, "Decrypt with generated keys") +action_list.insert(4, "Only create fresh keys") action_list.pack(fill='both') -submit_action = tk.Button(action, text="Begin Process", font=("Arial", "12")) +submit_action = tk.Button(action, text="Begin Process", font=("Arial", "12"), command=lambda: setup(action_list.curselection())) submit_action.pack() -modifiers = tk.Frame(frame, bg="white") +step_two =tk.Frame(frame, bg="white") +step_two.pack(fill="both") + +modifiers = tk.Frame(step_two, bg="white") modifiers.pack(fill="both") -file_label_text = "If you see this, the app broke" -file_instructions_text = "Separate filepaths with colons (:)" -file_label = tk.Label(modifiers, text=file_label_text, font=("Arial", "14")) -file_label.pack() -file_instructions = tk.Label(modifiers, text=file_instructions_text, font=("Arial", "11")) -file_instructions.pack() -file_input = tk.Entry(modifiers, font=("Arial", "12"), justify=tk.LEFT) -file_input.pack(fill=tk.X) -passcode_label_text = "If you see this, the app broke" -passcode_instructions_text = "CRITICAL: DO NOT FORGET YOUR PASSCODE. WITHOUT IT, YOUR DATA IS LOST." -passcode_label = tk.Label(modifiers, text=passcode_label_text, font=("Arial", "14")) -passcode_label.pack() -passcode_instructions = tk.Label(modifiers, text=passcode_instructions_text, font=("Arial", "11")) -passcode_instructions.pack() -passcode_input = tk.Entry(modifiers, font=("Arial", "12"), justify=tk.LEFT) -passcode_input.pack(fill=tk.X) +file_label = tk.Label(modifiers, text="If you see this, the app broke", font=("Arial", "14")) +file_instructions = tk.Label(modifiers, text="Separate filepaths with colons (:)", font=("Arial", "11")) +file_input = tk.Entry(modifiers, font=("Arial", "12"), justify=tk.CENTER, textvariable=tk.StringVar) +passcode_label = tk.Label(modifiers, text="If you see this, the app broke", font=("Arial", "14")) +passcode_instructions = tk.Label(modifiers, text="If you see this, the app broke", font=("Arial", "11")) +passcode_input = tk.Entry(modifiers, font=("Arial", "12"), justify=tk.CENTER, textvariable=tk.StringVar) + +save = tk.Frame(step_two, bg='white') +save.pack(fill='both') +save_label = tk.Label(save, text="Save location for keys", font=("Arial", "14")) +save_instructions = tk.Label(save, text="Save the keys to an empty folder, and store them somewhere secure\nIf other key files exist in the same folder, they will be overwritten", font=("Arial", "11")) +save_input = tk.Entry(save, font=("Arial", "12"), justify=tk.CENTER, textvariable=tk.StringVar) +submit = tk.Button(save, text="If you see this, the app broke", font=("Arial", "12"), command=lambda: go(mode=crypto_mode, save_folder=save_input.get(), target_file=file_input.get(), passkey=passcode_input.get())) root.mainloop() \ No newline at end of file diff --git a/initiate_key.py b/initiate_key.py @@ -6,7 +6,7 @@ from cryptography.hazmat.primitives.asymmetric import padding from cryptography.fernet import Fernet #rsa_key() generates a symmetric key as well as a public and private key -def rsa_key(): +def rsa_key(passkey, savefolder): # Generating the symmetric key for use encrypting the file symmetric_key = Fernet.generate_key() # Generating the private key object for use encrypting the symmetric key @@ -18,7 +18,7 @@ def rsa_key(): # Generating the public key object for use decrypting the symmetric key public_key = private_key.public_key() # Collecting user input to add a password to the private key for additional security - private_key_passcode = input("Private Key Password (CRITICAL: DO NOT FORGET. DATA WILL BE LOST): ") + private_key_passcode = passkey # Turning the private key object to readable text for export private_key_text = private_key.private_bytes( encoding=serialization.Encoding.PEM, @@ -30,10 +30,16 @@ def rsa_key(): encoding=serialization.Encoding.PEM, format=serialization.PublicFormat.SubjectPublicKeyInfo ) + # Checking the validity of the filepath provided + if savefolder[-1] != '/': + savefolder += '/' # Writing the keys to their respective files - with open('private_key.pem', 'wb') as private_file: + private_key_file = savefolder + 'private_key.pem' + public_key_file = savefolder + 'public_key.pem' + symmetric_key_file = savefolder + 'symmetric_key.key' + with open(private_key_file, 'wb') as private_file: private_file.write(private_key_text) - with open('public_key.pem', 'wb') as public_file: + with open(public_key_file, 'wb') as public_file: public_file.write(public_key_text) - with open('symmetric_key.key', 'wb') as symmetric_file: + with open(symmetric_key_file, 'wb') as symmetric_file: symmetric_file.write(symmetric_key) \ No newline at end of file