标签:ret util ogr 允许 inter 之一 pyc 实现 test
PyJWT
PyJWT
是一个Python库,允许您对JSON Web Tokens(JWT)进行编码和解码。JWT是一个开放的行业标准(RFC 7519),用于在双方之间安全地声明索赔。
安装
pip install pyjwt
如需了解更多,请参阅安装了解更多信息
>>> import jwt >>> encoded_jwt = jwt.encode({‘some‘: ‘payload‘}, ‘secret‘, algorithm=‘HS256‘) >>> encoded_jwt ‘eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg‘ >>> jwt.decode(encoded_jwt, ‘secret‘, algorithms=[‘HS256‘]) {‘some‘: ‘payload‘}
如果您计划使用某些数字签名算法(如RSA或ECDSA)进行编码或解码令牌,则需要安装 加密库。
pip install cryptography
pip install pycrypto ecdsa
一旦你已经安装了 pycrypto 和 ecdcsa,你可以在PyJWT中使用jwt.register_algorithm()。下面的示例代码将展示怎样配置PyJWT,去使用具有SHA256和EC与SHA256签名的RSA的传统实现。
import jwt
from jwt.contrib.algorithms.pycrypto import RSAAlgorithm
from jwt.contrib.algorithms.py_ecdsa import ECAlgorithm
jwt.register_algorithm(‘RS256‘, RSAAlgorithm(RSAAlgorithm.SHA256))
jwt.register_algorithm(‘ES256‘, ECAlgorithm(ECAlgorithm.SHA256))
标签:ret util ogr 允许 inter 之一 pyc 实现 test
原文地址:https://www.cnblogs.com/wangyuxing/p/9560692.html