ModuleNotFoundError:没有名为'Crypto'的模块

时间:2018-02-25 09:34:27

标签: python cryptography sha256 pycrypto rsa-sha256

我安装了Crypto模块和SHA256,但显示了ModuleNotFoundError : -

  

回溯(最近一次调用最后一次):文件“Digitalsig.py”,第1行,in          来自Crypto.Hash导入SHA256 ModuleNotFoundError:没有名为'Crypto'的模块

这是引用代码

from Crypto.Hash import SHA256
from Crypto.PublicKey import RSA
from Crypto import Random

random_generator = Random.new().read

#used to generate a keypair which contain a public and private key
keyPair = RSA.generate(1024,random_generator)
pubKey = keyPair.publicKey()

plainText = 'Hello World'
hashA = SHA256.new(plainText).digest()
digitalSignature = keyPair.sign(hashA,'')

print("Hash A: "+repr(hashA) + "\n");
print("Digital Signature: " + repr(digitalSignature) + "\n")

#Bob receives the plainText and digitalSignature from Alice 
#plainTextChanged ='Hello World'
hashB =SHA256.new(plainText).digest()
print("Hash B: " + repr(hashB) + "\n")

if(pubKey.verify(hashB, digitalSignature)):
    print("Match")
else:
    print("No Match")

1 个答案:

答案 0 :(得分:2)

首先使用pip安装模块

  1. 打开Cmd
  2. 写命令 SBC (它需要安装Microsoft Visual C ++ 14.0)
  3. 然后在您的代码中使用它,就像在上面的代码中一样使用