[pycrypto] Pycrypto question.

jd jdsw2002 at yahoo.com
Sun May 2 14:02:29 CST 2010

Hi everyone, 
   I am trying to implement a simple pub/private key scheme. Want to encrypt bunch of things and decrypt it using public key (which will be distributed). Pycrypto seems to be perfect. Here is the sample code.. butit fails when I try to decrypt using public key part. Any pointers/suggestions appreciated.

Thanks in advance.

Traceback (most recent call last):
  File "pub.py", line 24, in <module>
  File "build/bdist.linux-i686/egg/Crypto/PublicKey/pubkey.py", line 63, in decrypt
  File "build/bdist.linux-i686/egg/Crypto/PublicKey/RSA.py", line 184, in _decrypt
_fastmath.error: Private key not available in this object


from Crypto.Hash import MD5
from Crypto.PublicKey import RSA
from Crypto.Util.randpool import RandomPool

pool =  RandomPool()

# Generate keypair
RSAkey = RSA.generate(384, pool.get_bytes)   # This will take a while...
hash = MD5.new("AbCdEf1234").digest()
signature = RSAkey.sign(hash, "")
print signature
print RSAkey.verify(hash, signature)     # This sig will check out
print RSAkey.verify(hash[:-1], signature)# This sig will fai

print "Encrypted bytes" ,x
print "Decrypted again", RSAkey.decrypt(x)

# Got the public key part
pub = RSAkey.publickey()


More information about the pycrypto mailing list