figenc

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

commit 286e339a182da463f74aedbf11d07dadac00c2ac
Author: therealFIGBERT <naomi@Naomis-MacBook-Air.local>
Date:   Thu, 27 Jun 2019 19:22:30 -0700

First commit

Diffstat:
Adecrypt.py | 41+++++++++++++++++++++++++++++++++++++++++
Aencrypt.py | 38++++++++++++++++++++++++++++++++++++++
Aexport_json.py | 12++++++++++++
Ainitiate_key.py | 31+++++++++++++++++++++++++++++++
4 files changed, 122 insertions(+), 0 deletions(-)

diff --git a/decrypt.py b/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 + +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 + ) + ) + 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("Decrypt symmetric key (y/n): ") +if decrypt_symmetry == "y": + with open('symmetric_key.key', 'wb') as symmetric_file: + symmetric_file.write(symmetric_key_data) + print("Decryption completed. Nice job, hackerman.\n") +else: + print("Decryption completed. Nice job, hackerman.\n") +\ No newline at end of file diff --git a/encrypt.py b/encrypt.py @@ -0,0 +1,37 @@ +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 + +with open('public_key.pem', 'rb') as public_key_file: + public_key = serialization.load_pem_public_key( + public_key_file.read(), + backend=default_backend() + ) +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("Encrypt symmetric key (y/n): ") +if encrypt_symmetry == "y": + 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 diff --git a/export_json.py b/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/initiate_key.py b/initiate_key.py @@ -0,0 +1,30 @@ +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 + +symmetric_key = Fernet.generate_key() +private_key = rsa.generate_private_key( + public_exponent=65537, + key_size=2048, + backend=default_backend() +) +public_key = private_key.public_key() +private_key_passcode = input("Private Key Password: ") +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')) +) +public_key_text = public_key.public_bytes( + encoding=serialization.Encoding.PEM, + format=serialization.PublicFormat.SubjectPublicKeyInfo +) +with open('private_key.pem', 'wb') as private_file: + private_file.write(private_key_text) +with open('public_key.pem', 'wb') as public_file: + public_file.write(public_key_text) +with open('symmetric_key.key', 'wb') as symmetric_file: + symmetric_file.write(symmetric_key) +\ No newline at end of file