Base64 URLセーフエンコーダー&デコーダー
標準Base64をURLセーフBase64に変換、またはその逆。+、/を-、_に置き換え、=パディングを処理します。
100%クライアントサイド — データがデバイスから離れることはありません
URL-safe Base64 replaces + with - and / with _, and removes trailing = padding. This is used in JWT tokens, URL parameters, and cookies.
コード例
プロジェクトにすぐに使えるコードスニペットです。
Python
import base64
# Encode to URL-safe Base64 (replaces + with -, / with _)
text = "user@example.com?token=abc123"
safe = base64.urlsafe_b64encode(text.encode()).decode().rstrip("=")
print(safe) # dXNlckBleGFtcGxlLmNvbT90b2tlbj1hYmMxMjM
# Decode URL-safe Base64 (auto-handles missing padding)
decoded = base64.urlsafe_b64decode(safe + "===").decode("utf-8")
print(decoded) # user@example.com?token=abc123
# Convert standard Base64 to URL-safe
std = "abc+def/ghi=="
url_safe = std.replace("+", "-").replace("/", "_").rstrip("=")
print(url_safe) # abc-def_ghiよくある質問
以下を検索するか、よくある質問をご覧ください。
標準Base64はURLで特別な意味を持つ「+」と「/」文字を使用します。URLセーフBase64は「+」を「-」に、「/」を「_」に置き換え、末尾の「=」パディングを削除します。
Base64データをURL、クエリパラメータ、Cookieに含める必要がある場合は常にURLセーフBase64を使用してください。また、JWT(JSON Web Token)の標準でもあります。