PyJWT是一个Python库,可用于编码和解码JSON Web令牌(JWT)。JWT是一种开放的行业标准(RFC 7519),用于在两方之间安全地表示索赔。
pip3 install PyJWT
jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
jwt.decode(encoded_jwt, 'secret', algorithms=['HS256'])
λ python3
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import jwt
>>> encoded=jwt.encode({u'username':u'admin'},'uy8qz-!kru%*2h7$q&veq=y_r1abu-xd_219y%phex!@4hv62+',algorithm='HS256')
>>> print(encoded)
b'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImFkbWluIn0.GO6pyRekzKvi5ZYGyJV4xV4aKPw8Wvpuf46Y56fa7pc'
>>>