-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
32 lines (23 loc) · 968 Bytes
/
client.py
File metadata and controls
32 lines (23 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import socket
from secure import *
def client():
private_key, public_key = generateRSAKey()
c = socket.socket()
c.connect(('localhost', 9999))
# send client's public key to receive an encrypted session key from server
c.send(public_key.export_key())
enc_session_key = c.recv(2048)
#only client's private key can decrypt the encrypted session key
session_key = decryptSessionKey(enc_session_key, private_key)
# message from client to server
request = bytes(input('Client -> ').encode())
while request.lower().strip() != b"bye":
encrypted_request = encryptData(request, session_key)
c.send(encrypted_request)
# message from server to client
encrypted_response = c.recv(2048)
response = decryptData(encrypted_response, session_key)
print("Server:", response.decode())
request = bytes(input('Client -> ').encode())
if __name__ == "__main__":
client()