socket error in python 2.7, sending public rsa key to client -
i'm programming client-server communication encrypted rsa, using tcp sockets. generate public , private keys, when want exchange public keys between client , server error:
typeerror: must convertible buffer, not publickey
this server code:
import socket import rsa print "generating keys" (public, private) = rsa.newkeys(1024, poolsize=2) print "keys generated." tcpsocket = socket.socket(socket.af_inet, socket.sock_stream) tcpsocket.setsockopt(socket.sol_socket, socket.so_reuseaddr,1) tcpsocket.bind(("0.0.0.0", 1025)) tcpsocket.listen(1) print "waiting client..." (client, (ip, port)) = tcpsocket.accept() print "connection received from: ", ip client.send(public) #this error
i've tried line too:
client.send(str(public))
with can send public key, can't use encrypt data (because public key string).
thank !
you can use pickle or cpickle:
import cpickle to_send=cpickle.dumps(the_key) sock.send(to_send)
and unpickle it:
import cpickle s=sock.recv() key=cpickle.loads(s)
Comments
Post a Comment