-1

I am running into a problem with pycrypto public key encryption. Encryption works fine when I have the private key, but when I import just the public key encryption fails:

In [85]: import Crypto.PublicKey.RSA

In [86]: key = Crypto.PublicKey.RSA.importKey(open('/etc/pki/server.pub', 'r').read())

In [87]: key.

In [87]: key.encrypt('cheese', 32)

Out[87]: ('cheese',)

Last I checked that does not look encrypted. Can anyone help me see what I am missing in the pycrypto api?

1 Answers1

0

I tested your code (with a different RSA key of course), and it seems to work correctly. Are you sure that the keyfile is a RSA public key and is not empty? What do print key and key.has_private() return?

Roland Smith
  • 42,427
  • 3
  • 64
  • 94