4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

base64を理解する。

Last updated at Posted at 2020-08-26

base64とは

base64とは、64進数を意味する言葉で、すべてのデータをアルファベット(a~z, A~z)と数字(0~9)、一部の記号(+,/)の64文字で表すエンコード方式です。

base64ってなんぞ??理解のために実装してみた

関係図

base64.jpeg

.py
#文字列"Hello"をエンコード
encoded="Hello".encode()
print(encoded)
#b'Hello'

#-----------------
#"Hello"のBytesをbase64エンコード
base64_encoded=base64.b64encode(encoded)
print(base64_encoded)
#b'SGVsbG8='

#-----------------
#base64エンコードしたBytesをデコード
decoded=base64.b64decode(base64_encoded)
print(decoded)
#b'Hello'

#-----------------
#Bytesをデコード
string=decoded.decode()
print(string)
#'Hello'

参考

base64ってなんぞ??理解のために実装してみた
Python 3 での文字列とバイト列の相互変換と16進数表示
base64 --- Base16, Base32, Base64, Base85 データの符号化

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?