1

我有简单的 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)

当我尝试运行它时,我的 CLI 显示错误:

回溯(最后一次调用):
文件“otrsa.py”,第 6 行,在 impl = Crypto.PublicKey.RSA.RSAImplementation(use_fast_math = True) AttributeError: 'module' object has no attribute 'RSAImplementation'

我对 Python 真的很陌生,我不知道它是什么意思。我会感谢任何形式的帮助。

4

3 回答 3

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()

请注意,默认情况下,如果可用,将使用快速数学。如果它不可用,强制 use_fast_math 只会导致运行时错误。

于 2010-12-28T02:23:13.660 回答
0

嗯,我得到了同样的错误——文档和代码之间可能有些不匹配?

我用过的 pyCrypto 很少,我发现 M2Crypto 总体上是一个更好的库——你可能想尝试一下。

于 2010-12-28T00:42:53.400 回答
0

这意味着 Crypto.PublicKey.RSA 没有名为“RSAImplementation”的函数/变量

于 2010-12-28T00:46:18.210 回答