[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.
/Jd

===
Traceback (most recent call last):
  File "pub.py", line 24, in <module>
    pub.decrypt(x)
  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

#Randomize
pool =  RandomPool()
pool.randomize()
pool.stir_n(5)

# 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

x=RSAkey.encrypt("FooBar",0)
print "Encrypted bytes" ,x
print "Decrypted again", RSAkey.decrypt(x)

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



      


More information about the pycrypto mailing list