我目前正在使用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版本
对导出和导入RSA密钥的支持是在changelog中列出的版本2.2中实现的,因此除非您能够升级,否则您将走运。在
我通过
pip install pycryptodome
解决了这个问题相关问题 更多 >
编程相关推荐