「Python」Base64による文字列のエンコードとデコードサンプル
書式
base64.b64encode(文字列.encode())
テキスト文字列をencode()メソッドを使ってbyteデータに変換します
使用例
import base64
target = 'study skill in arkgame'
# string型をbytes型に変換
res = base64.b64encode(target.encode())
print(res)
# decode関数でbytes型をstring型に変換
print(res.decode())
import base64
target = 'study skill in arkgame'
# string型をbytes型に変換
res = base64.b64encode(target.encode())
print(res)
# decode関数でbytes型をstring型に変換
print(res.decode())
import base64 target = 'study skill in arkgame' # string型をbytes型に変換 res = base64.b64encode(target.encode()) print(res) # decode関数でbytes型をstring型に変換 print(res.decode())
実行結果
>python test.py
b’c3R1ZHkgc2tpbGwgaW4gYXJrZ2FtZQ==’
c3R1ZHkgc2tpbGwgaW4gYXJrZ2FtZQ==