模块'Crypto.PublicKey.RSA'没有属性'import_key'

问题描述 投票:0回答:1

我有一个C#应用程序,它使用以下公共密钥成功加密和解密(使用相应的私有密钥)。我使用以下代码在Python中使用相同的公钥进行加密。我收到以下错误:

模块'Crypto.PublicKey.RSA'没有属性'import_key'

我已推荐RSA - pycryptodome.readthedocs.io检查“ import_key”。它说extern_key (string or byte string)

注意:我已经安装了pycrypto 2.6.1。使用conda list验证。

如何解决此问题,以便Python可以使用C#应用程序成功使用的相同密钥?

Python代码

import Crypto
from Crypto.PublicKey import RSA
pubkey = 'BgIAAACkAABSU0ExAAQAAAEAAQB5ad3IFUIQ+NJeJEVlHJb0BaXhPCpeP+477ql+2dsNLzpn+3f2Lm5UWZhig60rx7/5/rAlAH+emU6WwOZNxtMtFbdu9CNBUjRp9FiEmJHZLaGqqmEFDyp287k3HVCFVzxxRAEy8ftL/q6KaE3KKrHoFiMozretUXulYy5OE1yR7w=='

import base64
decodedPublicKey = base64.b64decode(pubkey)
pub_key = RSA.import_key(decodedPublicKey)
encrypted = pub_key.encrypt('hello world', None)
print(encrypted)
text = pvt_key.decrypt(encrypted)
print(text)
python pycrypto
1个回答
0
投票

您最近安装了它吗?我们刚刚注意到昨天构建的Raspberry Pi设备存在问题。在/usr/local/lib/python3.5/dist-packages/Crypto/PublicKey文件夹中,许多文件(包括RSA.py)为空。几分钟前,我们刚刚卸载并重新安装了pycryptodome,并且文件不再为空。

© www.soinside.com 2019 - 2024. All rights reserved.