load_pem_private_key fails with ecdsa key of size 521
<p>I have the following two ECDSA private key for testing.</p>

<pre><code>from cryptography.hazmat.primitives.serialization import load_pem_private_key
from cryptography.hazmat.backends import default_backend


privateECDSA_openssh521 = b"""-----BEGIN EC PRIVATE KEY-----
MIHcAgEBBEIAjn0lSVF6QweS4bjOGP9RHwqxUiTastSE0MVuLtFvkxygZqQ712oZ
ewMvqKkxthMQgxzSpGtRBcmkL7RqZ94+18qgBwYFK4EEACOhgYkDgYYABAFpX/6B
mxxglwD+VpEvw0hcyxVzLxNnMGzxZGF7xmNj8nlF7M+TQctdlR2Xv/J+AgIeVGmB
j2p84bkV9jBzrUNJEACsJjttZw8NbUrhxjkLT/3rMNtuwjE4vLja0P7DMTE0EV8X
f09ETdku/z/1tOSSrSvRwmUcM9nQUJtHHAZlr5Q0fw==
-----END EC PRIVATE KEY------"""


privateECDSA_openssh384 = b"""-----BEGIN EC PRIVATE KEY-----
MIGkAgEBBDAtAi7I8j73WCX20qUM5hhHwHuFzYWYYILs2Sh8UZ+awNkARZ/Fu2LU
LLl5RtOQpbWgBwYFK4EEACKhZANiAATU17sA9P5FRwSknKcFsjjsk0+E3CeXPYX0
Tk/M0HK3PpWQWgrO8JdRHP9eFE9O/23P8BumwFt7F/AvPlCzVd35VfraFT0o4cCW
G0RqpQ+np31aKmeJshkcYALEchnU+tQ=
-----END EC PRIVATE KEY-----"""
</code></pre>

<p>with this information if I do. <code>load_pem_private_key(privateECDSA_openssh384, None, default_backend())</code> it works fine but if I do <code>load_pem_private_key(privateECDSA_openssh521, None, default_backend())</code></p>

<p>I get the following error </p>

<pre><code>    load_pem_private_key(privateECDSA_openssh521, None, default_backend())
  File "/usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/serialization.py", line 20, in load_pem_private_key
return backend.load_pem_private_key(data, password)
  File "/usr/lib/python2.7/dist-packages/cryptography/hazmat/backends/multibackend.py", line 282, in load_pem_private_key
return b.load_pem_private_key(data, password)
  File "/usr/lib/python2.7/dist-packages/cryptography/hazmat/backends/openssl/backend.py", line 1606, in load_pem_private_key
password,
  File "/usr/lib/python2.7/dist-packages/cryptography/hazmat/backends/openssl/backend.py", line 1802, in _load_key
self._handle_key_loading_error()
  File "/usr/lib/python2.7/dist-packages/cryptography/hazmat/backends/openssl/backend.py", line 1874, in _handle_key_loading_error
raise ValueError("Could not unserialize key data.")
ValueError: Could not unserialize key data.
</code></pre>

<p>I don't understand what is the problem.</p>

<p>Have tried to load your data and got the following error string <code>b'bad end line'</code></p>

<p>You have six dashes at the end line. Just fix it.</p>

<pre><code>&gt;&gt;&gt; privateECDSA_openssh521 = b"""-----BEGIN EC PRIVATE KEY-----
... MIHcAgEBBEIAjn0lSVF6QweS4bjOGP9RHwqxUiTastSE0MVuLtFvkxygZqQ712oZ
... ewMvqKkxthMQgxzSpGtRBcmkL7RqZ94+18qgBwYFK4EEACOhgYkDgYYABAFpX/6B
... mxxglwD+VpEvw0hcyxVzLxNnMGzxZGF7xmNj8nlF7M+TQctdlR2Xv/J+AgIeVGmB
... j2p84bkV9jBzrUNJEACsJjttZw8NbUrhxjkLT/3rMNtuwjE4vLja0P7DMTE0EV8X
... f09ETdku/z/1tOSSrSvRwmUcM9nQUJtHHAZlr5Q0fw==
... -----END EC PRIVATE KEY-----"""
&gt;&gt;&gt; load_pem_private_key(privateECDSA_openssh521, None, default_backend())
</code></pre>

<p>returns:</p>

<pre><code>&lt;cryptography.hazmat.backends.openssl.ec._EllipticCurvePrivateKey object at 0x109cda128&gt;
</code></pre>

python cryptography