AES decryption not working

I am developing a client / server application using sockets where the client sends encrypted JSON data using AES-256 encryption and the server takes over decrypting the received files and prints them out.

I tried this on localhost, which decrypted, but when I installed my Centos Server it didn't work. Encrypted data from the client is accepted 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 based on here

+3


source to share


1 answer


This issue is the compatibility version in the lambda unpad function:

Python 2

unpad = lambda s : s[0:-ord(s[-1])]

      



Python 3

unpad = lambda s : s[0:-s[-1]]

      

+3


source







All Articles