Search code examples
pythonpycrypto

python pycrypto: module' object has no attribute 'importKey'


I'm currently working with pycrypto and I want to import public key,but it can not work and raise some error: 'module' object has no attribute 'importKey''
I also use pycrypto in my other script,it works well,so I can not understand why this can not work.
my code that can't work is as following:

    from Crypto.PublicKey import RSA
    .............
    .............
    def task_name(task):
        username = task['user']
        taskintid = task['taskintid']
        data = '%s,%s' % (str(username), str(taskintid))
        user_id = task.get('op_user_id', '')
        db = get_db()

        ssh_key = db.ssh_key.find_one({'user_id': user_id})
        if ssh_key:
            try:
                public_key = RSA.importKey(ssh_key.get('ssh_key', ''))
                data = public_key.encrypt(data, 32)[0].encode('hex')
            except Exception, e:
                print e

    return "task-%s-%s" % (data, task['repeat_num'])

also, my python version is 2.6.5
=======================================
sorry,I forgot it, the pycrypto version is 2.0.1
because I have installed many packages,so I can not upgrage my pycrypto version


Solution

  • Support for exporting and importing RSA keys was implemented in version 2.2 listed in the changelog so unless you can upgrade you are out of luck.