Debian Codegraph @

docs/faq.rst

raw
1 Frequently Asked Questions
2 ==========================
3
4 How can I extract a public / private key from a x509 certificate?
5 -----------------------------------------------------------------
6
7 The ``load_pem_x509_certificate()`` function from ``cryptography`` can be used to
8 extract the public or private keys from a x509 certificate in PEM format.
9
10 .. code-block:: python
11
12 from cryptography.x509 import load_pem_x509_certificate
13
14 cert_str = b"-----BEGIN CERTIFICATE-----MIIDETCCAfm..."
15 cert_obj = load_pem_x509_certificate(cert_str)
16 public_key = cert_obj.public_key()
17 private_key = cert_obj.private_key()