Python PyCrypto和RSA问题
我有一个简单的RSA的Python脚本:
import Crypto.PublicKey.RSA
import rsakey
from Crypto.PublicKey import pubkey
# Some global stuff
impl = Crypto.PublicKey.RSA.RSAImplementation(use_fast_math = True)
RSAObj = impl.construct(rsakey.RSAKeys)
def decrypt(encrypted):
return RSAObj.decrypt(encrypted)
但是当我尝试运行它时,我的命令行界面显示了一个错误:
追踪记录(最近的调用在最前面):
文件 "otrsa.py",第6行,在 impl = Crypto.PublicKey.RSA.RSAImplementation(use_fast_math = True) 属性错误:'模块'对象没有属性 'RSAImplementation'
我对Python真的很陌生,不知道这是什么意思。 如果有人能帮我,我会非常感激。
3 个回答
0
这句话的意思是,Crypto.PublicKey.RSA 这个东西里没有一个叫做 'RSAImplementation' 的功能或者变量。
0
嗯,我也遇到了同样的错误——可能是文档和代码之间有些不匹配吧?
我用过的pyCrypto不多,但我发现M2Crypto这个库整体上要更好一些——你可以试试看。
3
Crypto.PublicKey.RSA 里有一个叫做 RSAImplementation 的类(可以查看这个链接了解更多:http://www.dlitz.net/software/pycrypto/apidoc/Crypto.PublicKey.RSA.RSAImplementation-class.html)。
以下代码在我的环境中运行正常(我使用的是 32 位 Windows 上的 Python 2.7.1):
import Crypto.PublicKey.RSA
impl = Crypto.PublicKey.RSA.RSAImplementation()
需要注意的是,如果有快速数学运算的功能,默认情况下会使用它。如果强制使用快速数学运算,但实际上没有这个功能,就会导致运行时错误。