Skip to content

Commit de7b25d

Browse files
Svetlin Nakovgitbook-bot
Svetlin Nakov
authored andcommitted
GitBook: [master] one page modified
1 parent 6947b54 commit de7b25d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

digital-signatures/rsa-sign-verify-examples.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -98,30 +98,31 @@ import binascii
9898

9999
# Generate 1024-bit RSA key pair (private + public key)
100100
keyPair = RSA.generate(bits=1024)
101+
pubKey = keyPair.publickey()
101102

102103
# Sign the message using the PKCS#1 v1.5 signature scheme (RSASP1)
103-
msg = b'A message for signing'
104+
msg = b'Message for RSA signing'
104105
hash = SHA256.new(msg)
105106
signer = PKCS115_SigScheme(keyPair)
106107
signature = signer.sign(hash)
107108
print("Signature:", binascii.hexlify(signature))
108109

109110
# Verify valid PKCS#1 v1.5 signature (RSAVP1)
110-
msg = b'A message for signing'
111+
msg = b'Message for RSA signing'
111112
hash = SHA256.new(msg)
112-
signer = PKCS115_SigScheme(keyPair)
113+
verifier = PKCS115_SigScheme(pubKey)
113114
try:
114-
signer.verify(hash, signature)
115+
verifier.verify(hash, signature)
115116
print("Signature is valid.")
116117
except:
117118
print("Signature is invalid.")
118119

119120
# Verify invalid PKCS#1 v1.5 signature (RSAVP1)
120121
msg = b'A tampered message'
121122
hash = SHA256.new(msg)
122-
signer = PKCS115_SigScheme(keyPair)
123+
verifier = PKCS115_SigScheme(pubKey)
123124
try:
124-
signer.verify(hash, signature)
125+
verifier.verify(hash, signature)
125126
print("Signature is valid.")
126127
except:
127128
print("Signature is invalid.")

0 commit comments

Comments
 (0)