Search code examples
pythonrsapycrypto

Python PyCrypto and RSA problem


I'e got simple RSA python script:

import Crypto.PublicKey.RSA
import rsakey
from Crypto.PublicKey import pubkey

# Some global stuff
impl = Crypto.PublicKey.RSA.RSAImplementation(use_fast_math = True)
RSAObj = impl.construct(rsakey.RSAKeys)

def decrypt(encrypted):
        return RSAObj.decrypt(encrypted)

and when I try to run it my CLI shows error:

Traceback (most recent call last):
File "otrsa.py", line 6, in impl = Crypto.PublicKey.RSA.RSAImplementation(use_fast_math = True) AttributeError: 'module' object has no attribute 'RSAImplementation'

I'm really new to Python and I don't know what it means. I would be thankful for any kind of help.


Solution

  • Crypto.PublicKey.RSA contains a class called RSAImplementation (see http://www.dlitz.net/software/pycrypto/apidoc/Crypto.PublicKey.RSA.RSAImplementation-class.html).

    The following works for me (in Python 2.7.1 on 32-bit Windows):

    import Crypto.PublicKey.RSA
    impl = Crypto.PublicKey.RSA.RSAImplementation()
    

    Note that, by default, fast math will be used if it is available. Forcing use_fast_math just causes a runtime error if it is not available.