Skip to content

Commit 06ca56a

Browse files
committed
Be specific for Python2 and Python3
1 parent 3cb92d5 commit 06ca56a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

docs/faq.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extract the public or private keys from a x509 certificate in PEM format.
99

1010
.. code-block:: python
1111
12+
# Python 2
1213
from cryptography.x509 import load_pem_x509_certificate
1314
from cryptography.hazmat.backends import default_backend
1415
@@ -17,9 +18,16 @@ extract the public or private keys from a x509 certificate in PEM format.
1718
public_key = cert_obj.public_key()
1819
private_key = cert_obj.private_key()
1920
20-
.. note:: These instructions are for Python 2.
21-
For Python 3, call ``encode()`` on ``cert_str`` to convert it
22-
into bytes before calling ``load_pem_x509_certificate``.
21+
.. code-block:: python
22+
23+
# Python 3
24+
from cryptography.x509 import load_pem_x509_certificate
25+
from cryptography.hazmat.backends import default_backend
26+
27+
cert_str = "-----BEGIN CERTIFICATE-----MIIDETCCAfm...".encode()
28+
cert_obj = load_pem_x509_certificate(cert_str, default_backend())
29+
public_key = cert_obj.public_key()
30+
private_key = cert_obj.private_key()
2331
2432
2533
I'm using Google App Engine and can't install `cryptography`, what can I do?

0 commit comments

Comments
 (0)