Hello i'm currently programming an application in python using Pyzmq for the communication between a PC client and a raspberry server. I need the PC client to send encrypted password to the raspberry serv. I will just post the RSA parts of my code, so if you need more informations or others parts of my program, please tell me.
So on my raspberry I do this to generate a RSA key:
from Crypto.Hash import MD5
from Crypto.PublicKey import RSA
from Crypto.Util import randpool
alea = randpool.RandomPool()
RSAKey = RSA.generate(1024,alea.get_bytes)
Then I get n and e parameters of this RSAKey which correspond at the Public Key to send them to my PC client.
When my PC receive these informations from the Raspberry, i construct the Public Key on the client:
from Crypto.Hash import MD5
from Crypto.PublicKey import RSA
def create_public_key(n,e):
key_params = (long(n),long(e))
return RSA.construct(key_params)
Then, when the user enters his password, I want to encrypt it:
def encrypt(text):
crypted = Client_Public_Key.encrypt(text,32)
return crypted[0]
Here is the crypted I get for the text "12345":
('C?\xd2\xca7j\xa0\x0cw\x8b+R"\xc37\xe8IR\xa1\x9fu\xe7v\x0c\xcaW-\xfcXb;]\x887\xc9\xfd\xf6\x0f\xe7\xae\x08\xfe\x0b\xaa*\xfa\x1b\x95:c\x99\xcb\xc6\x9f\x1d\xe1\x84\xa6\xcb\x8adh\x97w\xacR\xff\x8c\x80\xedX\xcc\xf3\xc3\x99\x99\xe9\x92\x8e\xbf]>5\xc5\xbe\x0e*G\xe2\xf2m\xdeN\xa4\x19\xbf\xd6\xd6\x9c\xba\xf9\xc8f\xa7_\xef\x84q\x877\x90\xd3\xd5\x93\xef\x81\xfc $\x9e\x03\t\x9c\xb4\xb1D,Q',)
I tried different way of encrypting (like Cipher's PKCS1_OAEP for example) and I always get these weird strings. Why I don't get a normal sequence of numbers ?
I would like to continue to use the decrypt function of this library because it's very fast, but the encrypt function keeps annoying me.
What can I do ? Thanks !
On my PC, I use Spyder with Python 2.7.14. On my Raspberry, I use Python 3.5.x.