commit 12b9a165d4736f8e885fa8309a572c774574f858
parent 7b785ca6b13a41d1be1cd77dde4349261c54f88f
Author: therealFIGBERT <naomi@Naomis-MacBook-Air.local>
Date: Thu, 27 Jun 2019 20:47:43 -0700
Configuring decrypt.py for use in application
Diffstat:
M | decrypt.py | | | 76 | +++++++++++++++++++++++++++++++++++++++++++--------------------------------- |
M | figEnc.py | | | 6 | ++++-- |
2 files changed, 47 insertions(+), 35 deletions(-)
diff --git a/decrypt.py b/decrypt.py
@@ -5,36 +5,46 @@ 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)
+def symmetric_dec():
+ 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_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)
-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
+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
+ )
+ )
+ 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
diff --git a/figEnc.py b/figEnc.py
@@ -1,4 +1,6 @@
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
+from encrypt import rsa_enc
+from decrypt import rsa_dec
+from decrypt import symmetric_dec
+\ No newline at end of file