python pycrypto: 模块对象没有属性 'importKey'
python pycrypto: module' object has no attribute 'importKey'
我目前正在使用 pycrypto,我想导入 public 密钥,但它无法工作并引发一些错误:'module' object has no attribute '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
解决了这个问题
我目前正在使用 pycrypto,我想导入 public 密钥,但它无法工作并引发一些错误:'module' object has no attribute '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