python pycrypto:模块“object”没有属性“importKey”

2024-09-29 17:22:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在使用pycrypto,我想导入公钥,但它无法工作,并引发一些错误:“module”对象没有属性“importKey”
我在我的另一个脚本中也使用了pycrypto,它工作得很好,所以我不明白为什么这个不能工作。
我无法运行的代码如下:

    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'])

另外,我的python版本是2.6.5
========================================
抱歉,我忘了,pycrypto的版本是2.0.1
因为我安装了很多软件包,所以我不能升级我的pycrypto版本


Tags: key版本idtaskdbdatagetusername
2条回答

对导出和导入RSA密钥的支持是在changelog中列出的版本2.2中实现的,因此除非您能够升级,否则您将走运。在

我通过pip install pycryptodome解决了这个问题

相关问题 更多 >

    热门问题