title: How to extract public key from a x509 certificate in python?
body: <p>Below shows the code example I followed, However I got error response as - "Unable to load certificate". </p>
  
  <pre><code>from cryptography.x509 import load_pem_x509_certificate
  from cryptography.hazmat.backends import default_backend
  
  cert_str = '-----BEGIN CERTIFICATE----- MIIDBTCCAe2gAwIBAgIQEsuEXXy6BbJCK3bMU6GZ/TANBgkqhkiG9w0BAQsFADAt... -----END CERTIFICATE-----';
  
  cert_obj = load_pem_x509_certificate(str.encode(cert_str), default_backend())
  public_key = cert_obj.public_key();
  </code></pre>
  
  <p>Error response</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\xampp1\htdocs\TestWorkPlace\TestPython\src\test1.py", line 10, in &lt;module&gt;
      cert_obj = load_pem_x509_certificate(str.encode(cert_str), default_backend())
    File "C:\Program Files (x86)\Python\lib\site-packages\cryptography\x509\base.py", line 43, in load_pem_x509_certificate
      return backend.load_pem_x509_certificate(data)
    File "C:\Program Files (x86)\Python\lib\site-packages\cryptography\hazmat\backends\multibackend.py", line 341, in load_pem_x509_certificate
      return b.load_pem_x509_certificate(data)
    File "C:\Program Files (x86)\Python\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 1175, in load_pem_x509_certificate
      raise ValueError("Unable to load certificate")
  ValueError: Unable to load certificate
  </code></pre>
  
  <p>Please help me to sort this issue. </p>