Base64 をテキストにデコードする方法
Base64 文字列を元の形式に戻す方法を学びます。パディングや無効な文字の扱いも含みます。
问题
Base64 エンコードされた文字列を受け取り、元の平文やバイナリデータを復元する必要があります。
前提条件
- Base64 アルファベットの理解
- パディング文字を識別できること
ステップ
-
1. Inspect the Base64 string
Confirm the string only contains valid Base64 characters (A-Z, a-z, 0-9, +, /) and optional = padding. Remove any whitespace or line breaks that may have been inserted for readability.
入力SGVsbG8sIFdvcmxkIQ==输出clean string -
2. Decode the string
Pass the cleaned string to a Base64 decoder. The decoder maps each character back to a 6-bit value, concatenates the bits, and splits them into 8-bit bytes.
入力SGVsbG8sIFdvcmxkIQ==输出Hello, World! -
3. Interpret the result
If the original data was text, display it as text using the correct character set. If it was binary, save it as a file or inspect the bytes. A garbled result usually means the wrong charset was assumed.
入力SGVsbG8sIFdvcmxkIQ==输出Hello, World!
期待される結果
エンコード前とまったく同じ、元のテキストまたはバイナリデータ。
よくあるエラー
- Decoding fails with 'invalid length'
- The string is not a multiple of 4. Add the missing = padding characters or re-encode the source.
- Output is garbled or shows replacement characters
- The original data was binary or used a different character set. Decode as bytes and inspect the raw output.
トラブルシューティング指引
- Strip all whitespace before decoding.
- If the string came from a URL, replace - with + and _ with / (URL-safe Base64) first.
セキュリティ上の制限
- Decoding Base64 reveals the original data instantly. Do not treat Base64 as a security barrier.