[pycrypto] Exporting/importing RSA publickeys ( fixed )

death Deathzor at Deathzor.com
Mon Apr 19 16:11:46 CST 2010


Tested and working code for anybody reading the mailing list after the
fact:
#pwd is the string where encrypting for sending 
PWD="encrypt this string for me plz";
# Generate private key For this node 
privatekeyClient = RSA.generate(1024)
#Generate publickey/identy for this node
publickeyClient = privatekeyClient.publickey()
#store the publickey 
stufftosend = {"e":publickeyClient.e,"n":publickeyClient.n} 
#create a new RSA publickey
publickeyClient2 = RSA.construct((stufftosend['n'],stufftosend['e']))
#encrypted_PWD
encrypted_PWD = publickeyClient2.encrypt(PWD, "")
print privatekeyClient.decrypt(encrypted_PWD)

Thnx for the advice. 


On Sun, 2010-04-18 at 19:10 +0200, Lorenz Quack wrote:
> Hello death!
> 
> The easiest way is to use the pickle module from the python standard library.
> untested pseudo code to show the general idea:
>  >>> key = Crypto.publicKey.RSA.generate(1024)
>  >>> pubkey = key.pubkey()
>  >>> pubkey_string = pickle.dumps(pubkey)
>  >>> socket.send(pubkey_string)
> and on the other side
>  >>> pubkey_string = socket.recv()
>  >>> pubkey = pickle.loads(pubkey_string)
> 
> an alternative is to access the relevant attributes of the pubkey and then use the construct method.
> again untested code:
>  >>> key = Crypto.publicKey.RSA.generate(1024)
>  >>> pubkey = key.pubkey()
>  >>> n, e = key.n, key.e
>  >>> # send n and e over socket
> and on the other side
>  >>> # get n and e from the socket
>  >>> pubkey = Crypto.publicKey.RSA.construct((n,e))
> 
> I hope this points you in the right direction.
> 
> sincerely yours
> //Lorenz
> 
> On 04/18/2010 01:18 AM, death wrote:
> >
> > i'm just wondering is there a way to import AND export the public keys
> > from RSA so i can, send the public key over a socket, import it on the
> > otherside so i can create a "secure" socket ( i know authentication is
> > not done in this process ).
> > the socket is still subject to a MIM attack, but this is not the point
> > at the moment
> >
> > it could be my inability to read the documentation but i found no way to
> > dump the key, and import it again.
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto

-- 
Death 

Email: Death at Deathzor.com
Msn: msn at Deathzor.com




More information about the pycrypto mailing list