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

RSA Signature Verification Example

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)
14 views1 page

RSA Signature Verification Example

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

from Crypto.

PublicKey import RSA


from [Link].pkcs1_15 import PKCS115_SigScheme
from [Link] import SHA256
import binascii

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


keyPair = [Link](bits=1024)

# Sign the message using the PKCS#1 v1.5 signature scheme (RSASP1)
msg = b'A message for signing'
hash = [Link](msg)
signer = PKCS115_SigScheme(keyPair)
signature = [Link](hash)
print("Signature:", [Link](signature))

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


msg = b'A message for signing'
hash = [Link](msg)
signer = PKCS115_SigScheme(keyPair)
try:
[Link](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 = [Link](msg)
signer = PKCS115_SigScheme(keyPair)
try:
[Link](hash, signature)
print("Signature is valid.")
except:
print("Signature is invalid.")

You might also like