This commit is contained in:
adii1823
2021-10-28 17:39:56 +05:30
parent 48cef734e0
commit 8704175145
15 changed files with 374 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
# jwt/token_rsa.py
import jwt
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
data = {'payload': 'data'}
def encode(data, priv_filename, algorithm='RS256'):
with open(priv_filename, 'rb') as key:
private_key = key.read()
return jwt.encode(data, private_key, algorithm=algorithm)
def decode(data, pub_filename, algorithm='RS256'):
with open(pub_filename, 'rb') as key:
public_key = key.read()
return jwt.decode(data, public_key, algorithms=[algorithm])
token = encode(data, 'jwt/rsa/key')
data_out = decode(token, 'jwt/rsa/key.pub')
print(data_out)