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.1.5.tar.gz
(5.3 kB
view details)
Built Distribution
File details
Details for the file pyjwt-rsa-0.1.5.tar.gz
.
File metadata
- Download URL: pyjwt-rsa-0.1.5.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c19c7c3c4e70161e6e932d99ce82e9b23e14cff545e8edebf29c27d851d921b9 |
|
MD5 | 9cd62ed401247ca69db92f6bd7cefa08 |
|
BLAKE2b-256 | bbdd21449dedd7646a42a3b20368d891340d0ea2a0259bcaceaa25efadee4c52 |
File details
Details for the file pyjwt_rsa-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: pyjwt_rsa-0.1.5-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbf904bc1f97efe32254bb6c950735d2643488de07ed99a19bbc9c77c25db310 |
|
MD5 | d2683cc3c76d514a539e3f6dddc980bc |
|
BLAKE2b-256 | 592be52e11a04693cb63e9700322552774c3d0b9d64eb4768031114fa1ecf68d |