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