Comments (3)
I have looked through the python-json
code and I think I have a working version to create a PEM
from n
/e
values:
# Copied from https://github.com/mpdavis/python-jose/blob/master/jose/utils.py - MIT License
def int_arr_to_long(arr):
return int("".join(["%02x" % byte for byte in arr]), 16)
# Copied from https://github.com/mpdavis/python-jose/blob/master/jose/utils.py - MIT License
def base64_to_long(data):
if isinstance(data, str):
data = data.encode("ascii")
# urlsafe_b64decode will happily convert b64encoded data
_d = base64.urlsafe_b64decode(bytes(data) + b"==")
return int_arr_to_long(struct.unpack("%sB" % len(_d), _d))
# Inspired by https://github.com/mpdavis/python-jose/blob/master/jose/backends/rsa_backend.py - MIT License
def convert_to_pem(n, e):
rsa_key = pyrsa.PublicKey(e=base64_to_long(e), n=base64_to_long(n))
der = rsa_key.save_pkcs1(format="DER")
return pyrsa_pem.save_pem(der, pem_marker="RSA PUBLIC KEY")
from pyjwt.
get_unverified_header
from jose import jwt
jwt.get_unverified_header(token)
import jwt
jwt.get_unverified_header(token)
base64url_decode
from jose.utils import base64url_decode
from jwt.utils import base64url_decode
Lines 28 to 33 in 7b4bc84
JWTError
jose's JWTError's subclasses are JWTClaimsError and ExpiredSignatureError.
from jose import JWTError
from jwt import InvalidTokenError
Line 9 in 72ad55f
pyjwt has ExpiredSignatureError, and multiple errors to cover JWTClaimsError.
from pyjwt.
For my needs, I just haven't figured out the replacement for jwk.construct() (docs).
I probably need to do something with PyJWK?
from jose import jwk
key = jwk.construct(data)
key.verify(msg, sig)
import jwt
obj = jwt.PyJWK(data)
# ???
Edit: This seems to work:
import jwt
obj = jwt.PyJWK(data)
alg_obj = obj.Algorithm
prepared_key = alg_obj.prepare_key(obj.key)
alg_obj.verify(msg, prepared_key, sig)
from pyjwt.
Related Issues (20)
- Why not sort_keys during json.dump ? HOT 2
- Unable to catch errors using flask @app.errorhandler HOT 1
- Add parameter for user-supplied timestamp when validating claims HOT 1
- SHA-256 not FIPS-202 compliant and a SHA-3 Update Required by NIST HOT 4
- Cryptography generated EC key is invalid HOT 1
- Ability to disable refresh & retry on `kid` mismatch HOT 4
- Security scan flags up the token being printed HOT 4
- options verify_exp not working HOT 1
- sharing namespace jwt conflict, is this possible to prevent, pip install pyJWT give no warning HOT 3
- Please stop validating that `iat <= now` by default HOT 3
- Got error: Algorithm 'ES256' could not be found. Do you have cryptography installed? HOT 3
- Remove algorithm parameter overwrite in PyJWS.encode HOT 1
- There should be a check on the type of algorithms in signature verification HOT 1
- Decoding fails with "Invalid payload string: must be a json object" when the JSON is an array HOT 1
- https://nvd.nist.gov/vuln/detail/CVE-2024-26130 update cryptography HOT 2
- When is python 3.12 expected to be released as a package on PIP? HOT 2
- Consider cryptography 42.x.x new validation HOT 2
- Make a release 2.9.0? Or create a checklist that contributors can help with? HOT 3
- Minimal example of implementation with encode and decode HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyjwt.