[英]AES Decryption doesn't work
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. 我正在使用套接字开发客户端 - 服务器应用程序,客户端使用Cipher AES-256加密发送加密的JSON数据,服务器负责解密收到的文件并将其打印出来。
I tried it on the localhost the decryption worked but when I set my Centos Server it didn't work. 我在localhost上尝试了解密工作,但是当我设置我的Centos Server时它没有用。 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()
This problem is a compatibility version in the unpad lambda function: 此问题是unpad lambda函数中的兼容版本:
Python 2 Python 2
unpad = lambda s : s[0:-ord(s[-1])]
Python 3 Python 3
unpad = lambda s : s[0:-s[-1]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.