如何从加密模块告诉服务器公钥?

时间:2020-07-17 17:12:07

标签: python cryptography public-key-encryption

我正在尝试使用cryptography模块使用加密功能在python中创建一个简单的Messenger。我已经对客户端和服务器进行了编码,但是现在我陷入其中,我告诉服务器我的公钥,以便服务器可以对组密钥或某种类型的密钥进行加密,客户端可以使用其私钥解密。我尝试使用常规类型的发送字符串来发送密钥,但是我只是在发送内存地址。我也尝试过将密钥保存到文件中并发送过来,但是那也不起作用。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您可以通过二进制文件发送密钥,客户端应将此二进制文件转换为utf8或您要使用的任何形式,这是向客户端发送加密数据的方案:

- server asks the client for the public key
- client sends public key with a binary file to the server
- server unpacks the binary file and transform it into another form
- server use public key extracted to encrypt data
- server sends encrypted data to the client
- client decrypt the encrypted data

您可以在另一侧做同样的事情