Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Generate a pub and privkey
- # openssl genrsa 2048 > priv.pem
- # cat priv.pem|openssl rsa -pubout > pub.pem
- # encode.py:
- import jwt
- pubkey = open("priv.pem",'r').read()
- key = "\n".join([l.lstrip() for l in pubkey.split("\n")])
- claim = {'test': 'hello'}
- token=jwt.encode(claim, key, algorithm='RS256')
- print(token.decode())
- # decode.py:
- import jwt
- pubkey = open("pub.pem", 'r').read()
- token = input()
- key = "\n".join([l.lstrip() for l in pubkey.split("\n")])
- claims = jwt.decode(token, key, algorithms=['RS256'])
- print(claims)
- # $ python3 encode.py | python3 decode.py ✔ 3182 21:45:39
- # {'test': 'hello'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement