Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. # Generate a pub and privkey
  2. # openssl genrsa 2048 > priv.pem
  3. # cat priv.pem|openssl rsa -pubout > pub.pem
  4.  
  5. # encode.py:
  6. import jwt
  7. pubkey = open("priv.pem",'r').read()
  8. key = "\n".join([l.lstrip() for l in pubkey.split("\n")])
  9. claim = {'test': 'hello'}
  10. token=jwt.encode(claim, key, algorithm='RS256')
  11. print(token.decode())
  12.  
  13. # decode.py:
  14. import jwt
  15. pubkey = open("pub.pem", 'r').read()
  16. token = input()
  17. key = "\n".join([l.lstrip() for l in pubkey.split("\n")])
  18. claims = jwt.decode(token, key, algorithms=['RS256'])
  19. print(claims)
  20.  
  21. # $ python3 encode.py | python3 decode.py  ✔  3182  21:45:39
  22. # {'test': 'hello'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement