RSA with PyCrypto
Tommy Lindgren
tomyltomyl at linuxlinux.nu
Wed Dec 11 12:53:36 EST 2002
Hi!
I am writing a P2P instant messenger and I would to like to encrypt
the messages using a symmetric crypto (DES3) and encrypt the DES3-key with
an asymmetric crypto (RSA). PyCrypto seems nice for this task, but I don't
understand how the RSA instances are supposed to exchange public keys.
An example:
from Crypto.PublicKey import RSA
from Crypto.Util.randpool import RandomPool
rpool = RandomPool()
# Generate keys
privkeyA = RSA.generate(368, rpool.get_bytes)
privkeyB = RSA.generate(368, rpool.get_bytes)
pubkeyA = privkeyA.publickey()
pubkeyB = privkeyB.publickey()
# Give B's public key to A... I think...
privkeyA.e = pubkeyB.e
privkeyA.n = pubkeyB.n
# A can now encrypt messages for B, as long as I don't give A's public key
# to B (which feels strange, but I am not too knowledgeable about the
# RSA algorithm)
msg = 'Follow the white rabbit.'
msgc = privkeyA.encrypt(msg, '')
msgd = privkeyB.decrypt(msgc)
So, is there a better way to exchange public keys?
TIA
--
Tommy Lindgren | o y @ i u . u
41A942131CAA5C | t m l l n x n
^C^C
More information about the Python-list
mailing list