from Crypto.Hash import SHA256
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
message = "I want this stream signed"
digest = SHA256.new()
digest.update(message)
# Read shared key from file
private_key = False
with open ("private_key.pem", "r") as myfile:
private_key = RSA.importKey(myfile.read())
# Load private key and sign message
signer = PKCS1_v1_5.new(private_key)
sig = signer.sign(digest)
# Load public key and verify message
verifier = PKCS1_v1_5.new(private_key.publickey())
verified = verifier.verify(digest, sig)
assert verified, 'Signature verification failed'
print('Successfully verified message')
我一直在尝试示例代码,但是当我上传Crypto库时会出错。我使用的是Python 3.6
错误是: 来自Crypto.Hash导入SHA256 ModuleNotFoundError:没有名为' Crypto'
的模块