figenc

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

commit 3493de6da3ce3c3c02bf2267d66915d2d914cf77
parent 286e339a182da463f74aedbf11d07dadac00c2ac
Author: therealFIGBERT <naomi@Naomis-MacBook-Air.local>
Date:   Thu, 27 Jun 2019 19:47:03 -0700

Configuring initiate_key.py for use in application

Diffstat:
AfigEnc.py | 2++
Minitiate_key.py | 54++++++++++++++++++++++++++++++------------------------
2 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/figEnc.py b/figEnc.py @@ -0,0 +1 @@ +import initiate_key +\ No newline at end of file diff --git a/initiate_key.py b/initiate_key.py @@ -5,26 +5,32 @@ 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 +def symmetric_enc(): + symmetric_key = Fernet.generate_key() + with open('symmetric_key.key', 'wb') as symmetric_file: + symmetric_file.write(symmetric_key) + +def rsa_enc(): + symmetric_key = Fernet.generate_key() + private_key = rsa.generate_private_key( + public_exponent=65537, + key_size=4096, + 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