【问题标题】:Python chat with Crypto module not decrypting与 Crypto 模块的 Python 聊天未解密
【发布时间】:2017-06-05 10:31:28
【问题描述】:

我用来学习套接字的 python 聊天正在运行,今天我开始实现 Crypto 模块来进行加密聊天。但我认为我在搞乱公钥和私钥。

当客户端连接到服务器时,它们会进行握手以交换其公钥。所以客户端有自己的密钥来解密加上服务器公钥来加密传出的消息。和服务器端:每个客户端都是一个线程,握手后存储自己的公钥来加密传出消息和服务器密钥来解密。

工作流程是(来自我的 POV):发送方客户端加密消息,发送到服务器,服务器使用自己的私钥解密,服务器使用自己的公钥加密消息给所有其他客户端。最后,收件人客户端使用服务器公钥解密消息。

使用send_allsend_all_no_room 方法向所有人发送消息时遇到的问题。有时消息被正确解密,但大多数时候没有正确解密。

我在哪一点丢失了正确的密钥?

这里有serverclientcomms(发送、接收方法)

考虑到我只为send_allsend_all_no_room 函数实现了自定义发送、接收、加密、解密方法。例如send_private_msg 将不起作用。

【问题讨论】:

    标签: python encryption


    【解决方案1】:

    问题出在send_all函数中:

    def send_all(self, message):
        """Send to all method, broadcast a message"""
        for sock in [client.sock for client in clients]:
            if sock != self.sock:
                message_encripted = self.encriptar(message,client)
                send(sock,message_encripted)
    

    for 循环的每次迭代都使用相同的clientsend_all_no_room函数也存在同样的问题。

    固定代码:

    def send_all(self, message):
        """Send to all method, broadcast a message"""
        for client in clients:
            if client is not self:
                message_encripted = self.encriptar(message,client)
                send(client.sock,message_encripted)
    

    【讨论】:

      猜你喜欢
      • 2021-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多