figenc

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

commit 7b785ca6b13a41d1be1cd77dde4349261c54f88f
parent 27f355510dc3f5fbd0604267c3fb7c448b225ced
Author: therealFIGBERT <naomi@Naomis-MacBook-Air.local>
Date:   Thu, 27 Jun 2019 20:19:25 -0700

Configuring encrypt.py for use in application

Diffstat:
Mencrypt.py | 70+++++++++++++++++++++++++++++++++++++++++-----------------------------
MfigEnc.py | 7+++++--
Minitiate_key.py | 7++++---
3 files changed, 50 insertions(+), 34 deletions(-)

diff --git a/encrypt.py b/encrypt.py @@ -5,33 +5,45 @@ 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) +def symmetric_enc(): + 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')) + with open(file_to_encrypt, 'wb') as write_file: + write_file.write(data) + print("Encryption successful. Proceed into cyberspace with confidence.\n") -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 +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() + ) + 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 + 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 diff --git a/figEnc.py b/figEnc.py @@ -1 +1,4 @@ -import initiate_key -\ No newline at end of file +from initiate_key import rsa_key +from initiate_key import symmetric_key +from encrypt import symmetric_enc +from encrypt import rsa_enc +\ No newline at end of file diff --git a/initiate_key.py b/initiate_key.py @@ -5,15 +5,16 @@ from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import padding from cryptography.fernet import Fernet -# symmetric_enc() generates a single symmetric key -def symmetric_enc(): +# symmetric_key() generates a single symmetric key +def symmetric_key(): # Generating the symmetric key symmetric_key = Fernet.generate_key() # Saving the symmetric key to the file symmetric_key.key with open('symmetric_key.key', 'wb') as symmetric_file: symmetric_file.write(symmetric_key) -def rsa_enc(): +#rsa_key() generates a symmetric key as well as a public and private key +def rsa_key(): # 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