JWT Generator
Generate signed JWT tokens with custom header, payload, and secret key.
⚠ For testing only — never expose real secrets.
Domande Frequenti
Implementazione del Codice
import jwt
import datetime
secret = "your-secret-key"
# Create a JWT (HS256)
payload = {
"sub": "user123",
"name": "Alice",
"iat": datetime.datetime.utcnow(),
"exp": datetime.datetime.utcnow() + datetime.timedelta(hours=1),
}
token = jwt.encode(payload, secret, algorithm="HS256")
print(token)
# Decode and verify
try:
decoded = jwt.decode(token, secret, algorithms=["HS256"])
print(decoded) # {'sub': 'user123', 'name': 'Alice', ...}
except jwt.ExpiredSignatureError:
print("Token has expired")
except jwt.InvalidTokenError:
print("Invalid token")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.