figenc

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

commit 9e5d4832ddf43fd95febe2b42f58dfbd6ef00619
parent 29517dafc8ce435d8e88fb0440e207852e716777
Author: therealFIGBERT <figbertwelner@gmail.com>
Date:   Wed,  3 Jul 2019 13:42:05 -0700

Adding Windows files

Diffstat:
AWindows/decrypt.py | 41+++++++++++++++++++++++++++++++++++++++++
AWindows/encrypt.py | 39+++++++++++++++++++++++++++++++++++++++
AWindows/export_json.py | 12++++++++++++
AWindows/figENC_Windows.py | 137+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AWindows/initiate_key.py | 46++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 275 insertions(+), 0 deletions(-)

diff --git a/Windows/decrypt.py b/Windows/decrypt.py @@ -0,0 +1,40 @@ +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives.asymmetric import rsa +from cryptography.hazmat.primitives import serialization +from cryptography.hazmat.primitives import hashes +from cryptography.hazmat.primitives.asymmetric import padding +from cryptography.fernet import Fernet + +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() + ) + 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/Windows/encrypt.py b/Windows/encrypt.py @@ -0,0 +1,38 @@ +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives.asymmetric import rsa +from cryptography.hazmat.primitives import serialization +from cryptography.hazmat.primitives import hashes +from cryptography.hazmat.primitives.asymmetric import padding +from cryptography.fernet import Fernet + +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(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/Windows/export_json.py b/Windows/export_json.py @@ -0,0 +1,11 @@ +import json + +#Data to export. The initial keys are used to select the data groups. +data = {} +#Configuring the script - filepath, data, etc. +filename = input("File path for exported json data: ") +data_header = input("Data to convert to json format: ") +data_info = data[data_header] +#Outputting the dictionary in json format +with open(filename, 'w') as file_export: + json.dump(data_info, file_export, indent=4, sort_keys=True) +\ No newline at end of file diff --git a/Windows/figENC_Windows.py b/Windows/figENC_Windows.py @@ -0,0 +1,136 @@ +from initiate_key import rsa_key +from encrypt import rsa_enc +from decrypt import rsa_dec +import tkinter as tk + +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") +canvas = tk.Canvas(root, height=700, width=650) +canvas.pack() +frame = tk.Frame(root) +frame.place(relwidth=1, relheight=1) + +header = tk.Label(frame, text="figENC\nIndustry leading encryption by FIGBERT", justify="center", font=("Arial", "24"), relief=tk.RAISED) +header.pack(fill="x", side="top", ipady="5") + +action = tk.Frame(frame) +action.pack(fill='both') +action_label = tk.Label(action, text="Action:", justify='left', font=("Arial", "14")) +action_label.pack() +action_list = tk.Listbox(action, selectmode="single", font=("Arial", "12"), height=4, bd=1, relief=tk.SUNKEN) +action_list.insert(1, "Encrypt with fresh keys") +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"), command=lambda: setup(action_list.curselection())) +submit_action.pack() + +step_two =tk.Frame(frame) +step_two.pack(fill="both") + +modifiers = tk.Frame(step_two) +modifiers.pack(fill="both") +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, relief=tk.SUNKEN) +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, relief=tk.SUNKEN) + +save = tk.Frame(step_two) +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, relief=tk.SUNKEN) +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/Windows/initiate_key.py b/Windows/initiate_key.py @@ -0,0 +1,45 @@ +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives.asymmetric import rsa +from cryptography.hazmat.primitives import serialization +from cryptography.hazmat.primitives import hashes +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(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 + private_key = rsa.generate_private_key( + public_exponent=65537, + key_size=4096, + backend=default_backend() + ) + # 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 = passkey + # Turning the private key object to readable text for export + private_key_text = private_key.private_bytes( + encoding=serialization.Encoding.PEM, + format=serialization.PrivateFormat.PKCS8, + encryption_algorithm=serialization.BestAvailableEncryption(bytes(private_key_passcode, 'utf-8')) + ) + # Turning the public key object to readable text for export + public_key_text = public_key.public_bytes( + 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 + 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_file, 'wb') as public_file: + public_file.write(public_key_text) + with open(symmetric_key_file, 'wb') as symmetric_file: + symmetric_file.write(symmetric_key) +\ No newline at end of file