0% found this document useful (0 votes)
62 views1 page

Signature Vérification RSA

This document generates a 1024-bit RSA key pair and uses it to sign a message with the PKCS#1 v1.5 signature scheme. It then verifies the signature is valid for the original message but invalid when the message is tampered with, demonstrating the signature verification process.

Uploaded by

Kabb kenken
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views1 page

Signature Vérification RSA

This document generates a 1024-bit RSA key pair and uses it to sign a message with the PKCS#1 v1.5 signature scheme. It then verifies the signature is valid for the original message but invalid when the message is tampered with, demonstrating the signature verification process.

Uploaded by

Kabb kenken
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

from Crypto.

PublicKey import RSA


from Crypto.Signature.pkcs1_15 import PKCS115_SigScheme
from Crypto.Hash import SHA256
import binascii

# Generate 1024-bit RSA key pair (private + public key)


keyPair = RSA.generate(bits=1024)

# Sign the message using the PKCS#1 v1.5 signature scheme (RSASP1)
msg = b'A message for signing'
hash = SHA256.new(msg)
signer = PKCS115_SigScheme(keyPair)
signature = signer.sign(hash)
print("Signature:", binascii.hexlify(signature))

# Verify valid PKCS#1 v1.5 signature (RSAVP1)


msg = b'A message for signing'
hash = SHA256.new(msg)
signer = PKCS115_SigScheme(keyPair)
try:
signer.verify(hash, signature)
print("Signature is valid.")
except:
print("Signature is invalid.")

# Verify invalid PKCS#1 v1.5 signature (RSAVP1)


msg = b'A tampered message'
hash = SHA256.new(msg)
signer = PKCS115_SigScheme(keyPair)
try:
signer.verify(hash, signature)
print("Signature is valid.")
except:
print("Signature is invalid.")

You might also like