title: How to load a RSA public key using Python's cryptography module
body: <p>I'm trying to load a public key using the <a href="https://cryptography.io/" rel="noreferrer">cryptography</a> module, this is what the key looks like:</p>
  
  <pre><code>&gt;&gt;&gt; print(pubkey)
  -----BEGIN RSA PUBLIC KEY-----
  MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+6gvHdCUCjnc4hSMwbdIIspk4
  69pVAzjjb8tDJsCH/QpiK9vXe4nDZ7p9kiw2ACw0fkWaPnApKBwXNB9Nd9Sf+XFt
  cIzdqKKBcAqZZCu2pA729amNRug9DoZdkstaBG+VfTxXhdzQRSTxxqJQWgdV8ejK
  kt4D1M6pAiTkAyD0eQIDAQAB
  -----END RSA PUBLIC KEY-----
  </code></pre>
  
  <p>I'm trying to load it using the <a href="https://cryptography.io/en/latest/hazmat/primitives/asymmetric/serialization/#cryptography.hazmat.primitives.serialization.load_pem_public_key" rel="noreferrer"><code>load_pem_public_key()</code></a> method:</p>
  
  <pre><code>&gt;&gt;&gt; from cryptography.hazmat.backends import default_backend
  &gt;&gt;&gt; from cryptography.hazmat.primitives.serialization import load_pem_public_key
  &gt;&gt;&gt; load_pem_public_key(pubkey, default_backend())
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/home/elias/.virtualenvs/ckpypkg/local/lib/python2.7/site-packages/cryptography/hazmat/primitives/serialization.py", line 24, in load_pem_public_key
      return backend.load_pem_public_key(data)
    File "/home/elias/.virtualenvs/ckpypkg/local/lib/python2.7/site-packages/cryptography/hazmat/backends/multibackend.py", line 285, in load_pem_public_key
      return b.load_pem_public_key(data)
    File "/home/elias/.virtualenvs/ckpypkg/local/lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1376, in load_pem_public_key
      self._handle_key_loading_error()
    File "/home/elias/.virtualenvs/ckpypkg/local/lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1595, in _handle_key_loading_error
      raise ValueError("Could not unserialize key data.")
  ValueError: Could not unserialize key data.
  </code></pre>
  
  <p>Am I doing something wrong? Is there something wrong with this key? Why can't it be unserialized?</p>
  
  <p>OpenSSL version:</p>
  
  <pre><code>$ openssl version
  OpenSSL 1.0.1f 6 Jan 2014
  </code></pre>
  
  <p><strong>UPDATE:</strong> I just tested the same code with a different key (the same one from <a href="https://stackoverflow.com/questions/10569189/how-to-read-a-rsa-public-key-in-pem-pkcs1-format">this other SO question</a>) and it worked, which makes this yet more puzzling: why it works for that key and not for mine?</p>