From 6b82a6353430df266b556600c55afb8f7c43761d Mon Sep 17 00:00:00 2001 From: Dominik Fuhrmann <dominik.fuhrmann1@gmail.com> Date: Fri, 27 Dec 2024 11:11:21 +0100 Subject: [PATCH] possible fix for base64 --- communication/client.py | 4 +++- communication/server.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/communication/client.py b/communication/client.py index cc42b43..fa78ebc 100644 --- a/communication/client.py +++ b/communication/client.py @@ -22,7 +22,9 @@ def load_public_key(): def encrypt_key_with_rsa(public_key, key): cipher = PKCS1_OAEP.new(public_key) encrypted_key = cipher.encrypt(key) - return encrypted_key + encrypted_key_base64 = base64.b64encode(encrypted_key).decode('utf-8') + return encrypted_key_base64 + # Encrypt entered user message according to selected algorithm and key length def encrypt_message(algorithm, key, message): diff --git a/communication/server.py b/communication/server.py index ddbb7f9..0e769f3 100644 --- a/communication/server.py +++ b/communication/server.py @@ -18,12 +18,14 @@ def load_private_key(): return private_key # Decrypt the received key using RSA private key -def decrypt_key_with_rsa(private_key, encrypted_key): +def decrypt_key_with_rsa(private_key, encrypted_key_base64): + encrypted_key = base64.b64decode(encrypted_key_base64) cipher = PKCS1_OAEP.new(private_key) key = cipher.decrypt(encrypted_key) logging.info(f"Decrypted RSA key: {key.hex()}") return key + # Decrypt received message using the key, depending on algorithm def decrypt_message(algorithm, key, encrypted_message): logging.info(f"Starting decryption with algorithm: {algorithm}") -- GitLab