🛠️ToolsShed

JWTジェネレーター

HS256署名付きJWTトークンを生成します。

⚠ テスト専用 — 実際の秘密鍵を公開しないでください。

よくある質問

コード実装

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.