RSA256 not supported despite having cryptography (was: pycrypto) installed
See original GitHub issuePython 3.2.3 on a RPi (Linux raspberrypi 3.18.11+ #781 PREEMPT Tue Apr 21 18:02:18 BST 2015 armv6l GNU/Linux
).
PyCrypto is installed:
pycrypto - Cryptographic modules for Python.
INSTALLED: 2.6.1 (latest)
python3-dev
and python3-crypto
are installed as well. Note: the same issue is present whether either of pycrypto
or python3-crypto
are installed, or both, or neither.
The following call crashes with an unsupported algorithm:
myjwt = jwt.encode(claim, private_key, algorithm='RS256', headers={"alg": "RS256", "typ": "JWT"}).decode('utf-8')
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/local/lib/python3.2/dist-packages/jwt/api_jws.py", line 96, in encode
alg_obj = self._algorithms[algorithm]
KeyError: 'RS256'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner
self.run()
File "/usr/lib/python3.2/threading.py", line 693, in run
self._target(*self._args, **self._kwargs)
File "galarmclock.py", line 241, in getcalendar
gauth.gettoken()
File "/root/galarmclock/googleauth.py", line 32, in gettoken
myjwt = jwt.encode(claim, private_key, algorithm='RS256', headers={"alg": "RS256", "typ": "JWT"}).decode('utf-8')
File "/usr/local/lib/python3.2/dist-packages/jwt/api_jwt.py", line 56, in encode
json_payload, key, algorithm, headers, json_encoder
File "/usr/local/lib/python3.2/dist-packages/jwt/api_jws.py", line 101, in encode
raise NotImplementedError('Algorithm not supported')
NotImplementedError: Algorithm not supported
Issue Analytics
- State:
- Created 8 years ago
- Reactions:6
- Comments:24 (5 by maintainers)
Top Results From Across the Web
Can't install pycrypto keep getting errors - Stack Overflow
pycrypto is an old library and don't know if it is being maintained. Use pycryptodome instead: pip install pycryptodome.
Read more >PyCryptodome Documentation - Read the Docs
One must avoid having both PyCrypto and PyCryptodome installed at the same time, ... Note that not all ciphers support all modes.
Read more >Installation — PyJWT 1.7.1 documentation - Read the Docs
If you are planning on encoding or decoding tokens using certain digital signature algorithms (like RSA or ECDSA), you will need to install...
Read more >Documentation: 15: F.28. pgcrypto - PostgreSQL
This module is considered “trusted”, that is, it can be installed by non-superusers who have CREATE privilege on the current database.
Read more >ModuleNotFoundError No module named Crypto - Edureka
Cipher import AES But I am getting this ... when I ran the code, ... I then removed pycrypto and installed it again...
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 FreeTop 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
Top GitHub Comments
Thanks for reporting @wsw70.
One small thing first. You don’t need to include the
headers
value in your call. Those headers will be automatically populated by PyJWT when it is creating the token. Theheaders
parameter is for adding additional header parameters besides just those required by the spec.Regarding your actual issue… some time ago we switched to using
cryptography
as the preferred cryptographic library for PyJWT. We switched for a number of reasons (most notably: the fact that cryptography is a much better implementation and is faster than PyCrypto). I strongly recommend that, if possible, you runpip install cryptography
and install the cryptography package. That will resolve the issue.If you are unable to install
cryptography
we do have legacy support for PyCrypto but this is not recommended unless you are on a platform (like Google App Engine) that doesn’t allow you to usecryptography
.You can setup the legacy support for algorithms by doing the following:
@mark-adams I use like this, but I catch the following error.
raise ValueError(‘Algorithm already has a handler.’) ValueError: Algorithm already has a handler.