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

标签 python pycrypto

我目前正在使用 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版本

最佳答案

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

关于python pycrypto : module' object has no attribute 'importKey' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29800675/

相关文章:

Python Pptx - 修改现有表

使用 PyCrypto AES 进行 Python 加密

python - 应用引擎 : ImportError: No module named Crypto. 哈希

algorithm - 是否有任何采用 7 字节 key 的 DES 库或代码?

cryptography - 如何使用ansible创建用户并设置密码?

python - 思考特征重要性的不同方式

python - 如何正确构建我的 PyQt GUI 并在传递 ui 时调用函数?

python - Django 模型数据库插入有时会因未知编码错误而失败

python - 删除列表中有条件的元素

java - Android RSA加密和Python解密