python
pip install python-jose
python
from jose import jwt
secret = 'your-secret-key'
payload = {'user_id': '123', 'username': 'john.doe'}
token = jwt.encode(payload, secret, algorithm='HS256')
print(token)
python
from jose import jwt
token = 'your-jwt-token'
secret = 'your-secret-key'
try:
payload = jwt.decode(token, secret, algorithms=['HS256'])
print('Token verification successful.')
print(payload)
except jwt.JWTError:
print('Token verification failed.')
python
from jose import jws
secret = 'your-secret-key'
data = {'user_id': '123', 'username': 'john.doe'}
signed_data = jws.sign(data, secret, algorithm='HS256')
print(signed_data)
try:
payload = jws.verify(signed_data, secret, algorithms=['HS256'])
print('Signature verification successful.')
print(payload)
except jws.JWSError:
print('Signature verification failed.')
python
from jose import jwe
secret = 'your-secret-key'
data = {'user_id': '123', 'username': 'john.doe'}
encrypted_data = jwe.encrypt(data, secret, alg='RSA-OAEP', enc='A256GCM')
print(encrypted_data)
try:
decrypted_data = jwe.decrypt(encrypted_data, secret, alg='RSA-OAEP', enc='A256GCM')
print('Data decryption successful.')
print(decrypted_data)
except jwe.JWEError:
print('Data decryption failed.')