python jwt测试

发布时间:2023-06-12 17:00

jwt是什么?

JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.

JWT.IO allows you to decode, verify and generate JWT.

JSON Web 令牌是一种开放的行业标准 RFC 7519方法,用于在两方之间安全地表示声明。

JWT.IO 允许您解码、验证和生成 JWT。

JSON Web Tokens - jwt.io\"icon-default.png?t=M4AD\"https://jwt.io/

python 环境中测试jwt

import os
import datetime
import jwt

secret_key = \"123456789\"
userCode = input(\"请输入用户名:\")
psw = input(\"请输入密码:\")

dtnow = datetime.datetime.strftime(datetime.datetime.now(),\'%Y-%m-%d %H:%M:%S\')
playloadStr = \"\"

if userCode == \"admin\" and psw == \"111111\":
    playloadStr = {\"name\": userCode, \"loginTime\": dtnow}
else:
    print(\"用户名或密码不正确!请重新输入!\")
    os._exit(0)  # 执行完成,退出程序

# https://pyjwt.readthedocs.io/en/latest/index.html
encoded_jwt = jwt.encode(playloadStr, secret_key, algorithm=\"HS256\")
print(\'加密token:\')
print(encoded_jwt)
dcoded_jwt = jwt.decode(encoded_jwt, secret_key, algorithms=[\"HS256\"])
print(\'解密token:\')
print(dcoded_jwt)

请输入用户名:admin
请输入密码:111111
加密token:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiYWRtaW4iLCJsb2dpblRpbWUiOiIyMDIyLTA2LTEyIDIxOjU2OjQxIn0.OscYKDcYfB5k0aH7op3-lXMumRo-LZ1Q2dZRNA3keFQ
解密token:
{\'name\': \'admin\', \'loginTime\': \'2022-06-12 21:56:41\'}

Process finished with exit code 0

\"python

 

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号