RSA helpers for PyJWT
Project description
Helpers for JWT tokens with RSA.
>>> from jwt_rsa.token import JWT
>>> from jwt_rsa.rsa import generate_rsa
>>>
>>> bits = 2048
>>>
>>> private_key, public_key = generate_rsa(bits)
>>>
>>> jwt = JWT(private_key, public_key)
>>>
>>> token = jwt.encode(foo='bar')
>>> result = jwt.decode(token)
>>> result
{'foo': 'bar', 'exp': 1525941819.638339, 'nbf': 1523349799.638342}
>>> # Expired token
>>> token = jwt.encode(foo='bar', expired=-1)
>>> jwt.decode(token)
Traceback (most recent call last):
...
jwt.exceptions.ExpiredSignatureError: Signature has expired
>>> # No verify token signature and expiration
>>> jwt.decode(token, verify=False)
{'foo': 'bar', 'exp': -1, 'nbf': 1523350046.935803}
Command line utilities
Module provides following utilities
jwt-rsa-keygen
Creates a new key pair:
$ jwt-rsa-keygen -h ±8 ?3 master
usage: jwt-rsa-keygen [-h] [-b BITS] [-P]
optional arguments:
-h, --help show this help message and exit
-b BITS, --bits BITS
-P, --pem
By default this utility return JSON-serialized key pair:
$ jwt-rsa-keygen ±8 ?3 master
{
"private": "MIIEvgIBADANBg......h3MBsSzx",
"public": "MIIBCgKCAQEAxUU......5niBEjAB"
}
Add parameter -P for return in PEM format:
$ jwt-rsa-keygen -P ±8 ?3 master
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDDeiI5V/O/Mbff
...
LGQgWf5ch0t1+Rh3tjIuuSc=
-----END PRIVATE KEY-----
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAw3oiOVfzvzG331nAL5hGHbblcCaV3pbfoCiFRgwpNPf7snIJtw97
...
3k2mMT1z6NFO6e6LMxg2zrqs3zgqwx5/9wIDAQAB
-----END RSA PUBLIC KEY-----
jwt-rsa-verify
Verify JSON serialized key pair:
$ jwt-rsa-keygen | jwt-rsa-verify ±8 ?3 master
INFO:root:Awaiting JSON on stdin...
INFO:root:Signing OK
INFO:root:Verifying OK
Or failed when key pair is invalid or doesn’t match:
$ jwt-rsa-keygen | sed 's/M/j/' | jwt-rsa-verify ±8 ?3 master
INFO:root:Awaiting JSON on stdin...
Traceback (most recent call last):
...
ValueError: Could not deserialize key data.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyjwt-rsa-0.3.6.tar.gz
(7.0 kB
view details)
Built Distribution
File details
Details for the file pyjwt-rsa-0.3.6.tar.gz
.
File metadata
- Download URL: pyjwt-rsa-0.3.6.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a38f37fdc8918f693f466fcd75ed215c6e4c8fc052b819d490445fa6466c536 |
|
MD5 | 7ebe36904bb6f46a0ba31aec74663b37 |
|
BLAKE2b-256 | d03bf13fb846cef0f036ca1ff7b576d0abd71ef0580ab3091df92f32a011369d |
File details
Details for the file pyjwt_rsa-0.3.6-py3-none-any.whl
.
File metadata
- Download URL: pyjwt_rsa-0.3.6-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c08eda09648b4c16c3c4cda966c81a880f9ac6e34e11fcd9cef376ea8f8ee5c |
|
MD5 | d957ecff13c0be53e3f8f7f36ad0aec9 |
|
BLAKE2b-256 | 48c4a4df6b18f9d0200295e71ea08f3a78e84d97bebf77677122a53892761ac0 |