doc error in example of exporting RSA key

Bug #1191411 reported by Tomas Vondra
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Python-Crypto
Fix Committed
Undecided
Unassigned

Bug Description

The current documentation contains this example of exporting RSA key

>>> from Crypto.PublicKey import RSA
>>>
>>> key = RSA.generate(2048)
>>> f = open('mykey.pem','w')
>>> f.write(RSA.exportKey('PEM'))
>>> f.close()
...
>>> f = open('mykey.pem','r')
>>> key = RSA.importKey(f.read())

which is incorrect and the example fails. It should use "key.exportKey" and not "RSA.exportKey".

Tags: doc
Revision history for this message
Darsey Litzenberger (dlitz) wrote :

Thanks for reporting! This will be fixed in the next release.

Pull request: https://github.com/dlitz/pycrypto/pull/43

Fix committed: https://github.com/dlitz/pycrypto/commit/f9a0fc77e1c8847c1a17503e5a1b86a409b8cb2d

Changed in pycrypto:
status: New → Fix Committed
Revision history for this message
Marco Herrero (helmetk) wrote :

"key.exportKey" returns a byte string, but the file is opened in string mode 'w', so the example fails. It should be changed to 'wb'
f = open('mykey.pem','wb')

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.