From 1ffdf6eca14e423b32ef3ac59bf64cff1d2db645 Mon Sep 17 00:00:00 2001 From: vSpaike <153102900+vSpaike@users.noreply.github.com> Date: Sat, 25 Jan 2025 01:11:26 +0100 Subject: [PATCH] P2 finito tout marche p5 --- RSA/client/main.py | 6 +++++- RSA/server/main.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/RSA/client/main.py b/RSA/client/main.py index 0225009..e024c1e 100644 --- a/RSA/client/main.py +++ b/RSA/client/main.py @@ -1,16 +1,20 @@ from flask import * -import ssl import requests import rsa import urllib3 +# Open public key of the server with open("ssl/server_public.pem","r") as f_public: pubi_k = rsa.PublicKey.load_pkcs1(f_public.read()) message = "Hello World !".encode() +# Encrypt the message with the public key of the server encrypt_message= rsa.encrypt(message,pubi_k) +# Delete error in the terminal urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + +# Send the request response = requests.post('https://localhost:5000/data',data=encrypt_message, verify="ssl/CA.crt") print(response.json()) diff --git a/RSA/server/main.py b/RSA/server/main.py index 3d7da7a..9c29c8e 100644 --- a/RSA/server/main.py +++ b/RSA/server/main.py @@ -18,10 +18,14 @@ def index(): @app.route('/data', methods=['POST']) def receive(): try: + # Receive message from the client encrypted_message = request.data + + # Open our private key with open("ssl/server_private.pem","r") as f_public: pubi_k = rsa.PrivateKey.load_pkcs1(f_public.read()) + # Decrypt the message and post-it decrypt_message = rsa.decrypt(encrypted_message,pubi_k).decode() print("Message received :",decrypt_message) return jsonify({'status': 'success', 'decrypted_message': decrypt_message}), 200