def sign():
from Crypto.Hash import SHA256
from Crypto.PublicKey import RSA
key = RSA.generate(2048)
public = key.publickey().exportKey('PEM').decode('ascii')
private = key.exportKey('PEM').decode('ascii')
text = 'abcdefgh'.encode('utf-8')
hash = SHA256.new(text).digest()
signature = key.sign(hash, '')
print('signature=', signature)
# Verify
# Knowing the public key, it is easy to verify a message.
# The plain text is sent to the user along with the signature.
# The receiving side calculates the hash value and then uses the public key verify() method to validate its origin.
评论列表
文章目录