Base64とは?
- 知る
- 使う
開発者向けの資料やAPIで、よく見かける「Base64」。何のためのものか、ファイルとBase64を相互変換する を使う前に、基本を知っておきましょう。
Base64とは
画像やPDFなどのデータ(バイナリ)を、英数字と少しの記号だけで表した文字列にする方式です。使う文字は、英字の大文字・小文字、数字、そして「+」「/」と、末尾の「=」です。
なぜ必要か
メールの本文や、一部の通信の仕組みは、文字しか扱えません。バイナリのデータをそのまま入れると、壊れてしまいます。Base64で文字にすれば、文字だけの場所にも、安全に入れられます。
手順(試してみる)
- 「向きを選ぶ」で、「ファイル → Base64」を選びます。
- 小さな画像かテキストを、「ファイルを1つ選ぶ」で選びます。
- 「変換後のBase64」に出る、文字列を見てみましょう。
Base64の特徴
- 元に戻せる:変換前のデータに、完全に戻せる。
- 文字だけで表せる:どこにでも貼り付けられる。
- 容量が増える:約1.3倍になる。
- 暗号ではない:誰でも、元に戻せる。
よくある使われ方
- メールで、添付ファイルを送る仕組み
- HTMLやCSSに、小さな画像を埋め込む(データURL)
- APIで、ファイルを文字としてやりとりする
- 設定ファイルに、バイナリを入れる
「暗号化」との違い
Base64は、データを別の形で表しているだけで、鍵がなくても、誰でも元に戻せます。パスワードや秘密の情報を、Base64にしても、守られません。
見分け方
- 英数字と「+」「/」だけでできている
- 末尾に「=」が付くことがある
- 長い、意味不明な文字の並び
例
APIの説明に、「画像はBase64で送る」とあった。このツールで、画像をBase64にして、確かめた。
つまずきやすい点
- 暗号と勘違いする:セキュリティの対策にはならない。
- 改行が入っている:メール用などで、76文字ごとに改行が入る場合がある。
よくある質問
Base64にすると、容量は小さくなりますか?
いいえ。約1.3倍に増えます。
まとめ
Base64は、データを文字にする方式。暗号ではなく、容量が増えることを覚えておきましょう。
ファイルとBase64を相互変換するを使う(無料)あわせて使えるツール
- ファイルのハッシュ値を調べる(SHA-256):ファイルのハッシュ値を調べて、照合します。
- CSVとJSONを相互変換する:CSVとJSONを、すぐに相互変換します。
- ファイルをZIPにまとめる:複数のファイルを、1つのZIPにまとめます。
同じツールの、ほかの解説
What Is Base64?
- Learn
- Use
"Base64" is often seen in developer documentation and APIs. Before using Convert Files and Base64, here are the basics of what it is for.
What Base64 is
A method of turning data (binary) such as images and PDFs into a string using only letters, digits and a few symbols. The characters used are upper and lower case letters, digits, "+" and "/", and "=" at the end.
Why it is needed
Email bodies and some communication mechanisms can handle only text. Putting binary data in as it is would corrupt it. Turned into text with Base64, it can be safely put even in text-only places.
Steps (trying it)
- For "Direction", choose "File → Base64".
- Choose a small image or text with "Choose one file".
- Look at the string that appears under "Base64 after conversion".
Characteristics of Base64
- Reversible: it can be returned fully to the data before conversion.
- Expressed in text only: can be pasted anywhere.
- Size increases: about 1.3 times.
- Not a cipher: anyone can restore it.
Common uses
- The mechanism for sending attachments by email
- Embedding small images in HTML or CSS (data URLs)
- Exchanging files as text through APIs
- Putting binary in configuration files
Difference from "encryption"
Base64 only expresses data in another form, and anyone can restore it without a key. Putting a password or secret information into Base64 does not protect it.
How to recognise it
- Made only of letters, digits, "+" and "/"
- Sometimes ends with "="
- A long, meaningless line of characters
Example
An API description said "send images in Base64". Used this tool to turn an image into Base64 and see.
Common stumbling blocks
- Mistaking it for encryption: it is no security measure.
- Line breaks included: for email and the like, line breaks may be inserted every 76 characters.
Frequently asked questions
Does Base64 make the size smaller?
No. It grows to about 1.3 times.
Summary
Base64 is a method of turning data into text. Remember it is not a cipher and increases size.
Use "Convert Files and Base64" (free)Tools that go well with this
- Check a File's Hash (SHA-256): Calculate a file's hash and compare it.
- Convert CSV and JSON: Convert between CSV and JSON instantly.
- Make a ZIP File: Pack several files into one ZIP.