-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient_cli.py
More file actions
31 lines (22 loc) · 777 Bytes
/
client_cli.py
File metadata and controls
31 lines (22 loc) · 777 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
from client import *
from crypt0graphy import *
crypto.pubrsakey = './RSAkey/server/public'
crypto.prirsakey = './RSAkey/client/private'
s = connect()
data, rk = DHc(s.recv(1024))
s.sendall(data)
print("Shared Key :", U.long_to_bytes(rk))
key = SHA256.new(U.long_to_bytes(rk))
aes = AES.new(key.digest(), AES.MODE_EAX)
while True:
data = input("Message to server : ").encode()
aes = AES.new(key.digest(), AES.MODE_EAX)
s.sendall(aes.nonce+aes.encrypt(data))
if data.strip() == b'Exit': break
edata = s.recv(1024)
nonce, edata = edata[:16], edata[16:]
aes = AES.new(key.digest(), AES.MODE_EAX, nonce=nonce)
data = aes.decrypt(edata).decode()
if data.strip() == "Exit":
break
print("Response from server :", data.strip())