Reputation: 101
I am developing a client-server application using sockets where the client sends encrypted JSON data using Cipher AES-256 encryption and the server takes in charge of decrypting those files received and print them out.
I tried it on the localhost the decryption worked but when I set my Centos Server it didn't work. The encrypted data coming from the client are received but not decrypted.
here is the server code:
Server code
#!/usr/bin/python
import socket
import threading
import Encryption
class ThreadedServer(object):
def __init__(self, host, port):
self.host = host
self.port = port
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.bind((self.host, self.port))
def listen(self):
self.sock.listen(5)
while True:
client, address = self.sock.accept()
client.settimeout(60)
threading.Thread(target = self.listenToClient,args = (client,address)).start()
def listenToClient(self, client, address):
size = 4096
while True:
print("Receiving")
try:
data = client.recv(size)
if data:
cipher = Encryption.Encryption('mysecretpassword')
jsondata = cipher.decrypt(data)
print(jsondata)
self.request.close()
else:
raise socket.error('Client disconnected')
except:
client.close()
return False
if __name__ == "__main__":
ThreadedServer(adress,port).listen()
and the Encryption file is inspired from here
Upvotes: 4
Views: 595
Reputation: 101
This problem is a compatibility version in the unpad lambda function:
Python 2
unpad = lambda s : s[0:-ord(s[-1])]
Python 3
unpad = lambda s : s[0:-s[-1]]
Upvotes: 4