gpt4 book ai didi

python - ModuleNotFoundError : No module named 'Crypto'

转载 作者:行者123 更新时间:2023-12-03 23:55:32 29 4
gpt4 key购买 nike

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

Traceback (most recent call last): File "Digitalsig.py", line 1, in from Crypto.Hash import SHA256 ModuleNotFoundError: No module named '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")

最佳答案

首先使用 pip 安装一个模块

  • 打开命令
  • 写命令pip install pycrypto(需要安装 Microsoft Visual C++ 14.0)
  • 然后在您的代码中使用它,就像您在上面的代码中使用的一样
  • 关于python - ModuleNotFoundError : No module named 'Crypto' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48972115/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com