ModuleNotFoundError: No module named 'Crypto'
Asked Answered
N

1

5

I installed Crypto module and SHA256 but showing ModuleNotFoundError :-

Traceback (most recent call last): File "Digitalsig.py", line 1, in from Crypto.Hash import SHA256 ModuleNotFoundError: No module named 'Crypto'

Here is the refrence code

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")
Necessary answered 25/2, 2018 at 9:34 Comment(2)
Did you check that the module is installed? Is it installed in the right environment (Python2/Python3 for instance)?Cyclograph
yes i have seen that..it is in correct environmentNecessary
F
6

First install a module using pip

  1. Open Cmd
  2. write command pip install pycrypto (It require installation of Microsoft Visual C++ 14.0)
  3. Then use it in your code as you use in your code above
Flaring answered 25/2, 2018 at 9:38 Comment(1)
use pycryptodome, the newer, less vulnerable, official, and supported version. pip install pycryptodome pycryptodome.readthedocs.io/en/latest/src/faq.html#Necromancy

© 2022 - 2024 — McMap. All rights reserved.