Problem with private_key.pem
See original GitHub issueI have done some tests with push notification and works. But when I integrate with django, I get this error:
File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/pywebpush/__init__.py", line 359, in webpush
vv = Vapid.from_string(private_key=vapid_private_key)
File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/py_vapid/__init__.py", line 142, in from_string
return cls.from_der(pkey)
File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/py_vapid/__init__.py", line 99, in from_der
backend=default_backend())
File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/cryptography/hazmat/primitives/serialization.py", line 28, in load_der_private_key
return backend.load_der_private_key(data, password)
File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/cryptography/hazmat/backends/multibackend.py", line 323, in load_der_private_key
return b.load_der_private_key(data, password)
File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1018, in load_der_private_key
password,
File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1160, in _load_key
self._handle_key_loading_error()
File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1229, in _handle_key_loading_error
raise ValueError("Could not deserialize key data.")
ValueError: Could not deserialize key data.
Why?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
For valid PEM I get unable to load private key by openssh
The issue is that ssh-keygen generates an SSH key, while openssl rsa doesn't read SSH keys - it can read PKCS#1 or PKCS#8....
Read more >Import of OpenSSl private key (pem) fails · Issue #191 - GitHub
I got an RSA private key in pem format that can't be loaded by KeyStore Explorer, however openssl rsa -text -in filename works...
Read more >Unable to load Private Key. (PEM routines:PEM_read_bio:no ...
Open the key file in Notepad++ and verify the encoding. If it says UTF-8-BOM then change it to UTF-8. Save the file and...
Read more >Error: "Invalid private key, or PEM pass phrase required for ...
4. Reinstall the certificate key pair. Problem Cause. This issue is caused because of hidden space control characters within the key.
Read more >What to Do if OpenSSL Does Not Find Your Private Key
The file for the private key contained a private key, but OpenSSL could somehow not find it. As it turns out, OpenSSL needs...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Cool. No worries about the keys, I’m sure I can duplicate the problem.
I’m not sure. The error is happening inside of the cryptography library, so there could be a number of reasons.
openssl ec -inform pem -in YourKeyFile.pem -text -nooutit should produce something like:
If not, the file may not be a proper key.
If that does work, (and if I understand that you’re able to send push notifications using something like
pywebpush, just not if the library is integrated into django), then I’ve no idea. It may be a library version conflict, or some monkey patch, or anything, really. (cryptography and openssl can be terrible about randomly changing how things work via “minor” updates)I don’t have a lot of time right now to dig into this, but I’ll try to get to it as soon as I can.