Skip to content

Commit 539c54a

Browse files
committed
Fix #170: mistake in examples of documentation
Strings need to be encoded into bytes before the RSA module can operate on them.
1 parent b81e317 commit 539c54a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

doc/usage.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ You can create a detached signature for a message using the
170170
:py:func:`rsa.sign` function:
171171

172172
>>> (pubkey, privkey) = rsa.newkeys(512)
173-
>>> message = 'Go left at the blue tree'
173+
>>> message = 'Go left at the blue tree'.encode()
174174
>>> signature = rsa.sign(message, privkey, 'SHA-1')
175175

176176
This hashes the message using SHA-1. Other hash methods are also
@@ -182,21 +182,21 @@ It is possible to calculate the hash and signature in separate operations
182182
private key on remote server). To hash a message use the :py:func:`rsa.compute_hash`
183183
function and then use the :py:func:`rsa.sign_hash` function to sign the hash:
184184

185-
>>> message = 'Go left at the blue tree'
185+
>>> message = 'Go left at the blue tree'.encode()
186186
>>> hash = rsa.compute_hash(message, 'SHA-1')
187187
>>> signature = rsa.sign_hash(hash, privkey, 'SHA-1')
188188

189189
In order to verify the signature, use the :py:func:`rsa.verify`
190190
function. This function returns True if the verification is successful:
191191

192-
>>> message = 'Go left at the blue tree'
192+
>>> message = 'Go left at the blue tree'.encode()
193193
>>> rsa.verify(message, signature, pubkey)
194194
True
195195

196196
Modify the message, and the signature is no longer valid and a
197197
:py:class:`rsa.pkcs1.VerificationError` is thrown:
198198

199-
>>> message = 'Go right at the blue tree'
199+
>>> message = 'Go right at the blue tree'.encode()
200200
>>> rsa.verify(message, signature, pubkey)
201201
Traceback (most recent call last):
202202
File "<stdin>", line 1, in <module>

0 commit comments

Comments
 (0)