Pyjwt ,python jwt ,jwt

pip install Pyjwt

 

不错的jwt 文章:

https://www.cnblogs.com/wayneiscoming/p/7513487.html

 


Sample
import jwt import time secret
="b'\x7d\xef\x87\xd5\xf8\xbb\xff\xfc\x80\x91\x06\x91\xfd\xfc\xed\x69'" print(secret.encode('utf-8')) expire_time = int(time.time()+3600) encode_str=jwt.encode( { "id":123123123, "exp":expire_time } , secret,#秘钥 algorithm='HS256' ) str_encode=str(encode_str,encoding='ascii') print(str_encode) info=jwt.decode(encode_str,secret,algorithms='HS256') print(info)

 

JSON WEB TOKENS


http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html
json web tokens

 

 

地址:https://www.npmjs.com/package/jwt-simple

jwt-simple
JWT(JSON Web Token) encode and decode module for node.js.

Install
$ npm install jwt-simple
Usage
var jwt = require('jwt-simple');
var payload = { foo: 'bar' };
var secret = 'xxx';
 
// HS256 secrets are typically 128-bit random strings, for example hex-encoded:
// var secret = Buffer.from('fe1a1915a379f3be5394b64d14794932', 'hex')
 
// encode
var token = jwt.encode(payload, secret);
 
// decode
var decoded = jwt.decode(token, secret);
console.log(decoded); //=> { foo: 'bar' }
decode params
/*
 * jwt.decode(token, key, noVerify, algorithm)
 */
 
// decode, by default the signature of the token is verified
var decoded = jwt.decode(token, secret);
console.log(decoded); //=> { foo: 'bar' }
 
// decode without verify the signature of the token,
// be sure to KNOW WHAT ARE YOU DOING because not verify the signature
// means you can't be sure that someone hasn't modified the token payload
var decoded = jwt.decode(token, secret, true);
console.log(decoded); //=> { foo: 'bar' }
 
// decode with a specific algorithm (not using the algorithm described in the token payload)
var decoded = jwt.decode(token, secret, false, 'HS256');
console.log(decoded); //=> { foo: 'bar' }
Algorithms
By default the algorithm to encode is HS256.

The supported algorithms for encoding and decoding are HS256, HS384, HS512 and RS256.

// encode using HS512
jwt.encode(payload, secret, 'HS512')
jwt-simple

 

 

 

 

 

import python_jwt as jwt, Crypto.PublicKey.RSA as RSA, datetime
key = RSA.generate(2048)
priv_pem = key.exportKey()
pub_pem = key.publickey().exportKey()
payload = { 'foo': 'bar', 'wup': 90 };
priv_key = RSA.importKey(priv_pem)
pub_key = RSA.importKey(pub_pem)
token = jwt.generate_jwt(payload, priv_key, 'RS256', datetime.timedelta(minutes=5))
header, claims = jwt.verify_jwt(token, pub_key, ['RS256'])
for k in payload: assert claims[k] == payload[k]

更多:https://pypi.org/project/python_jwt/2.0.1/
另一种

 

转载于:https://www.cnblogs.com/yanxiatingyu/p/10220428.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值