Python ---base64加密、解密

base64既能加密又能解密,
一般傳輸數據時會用到,加密完都是字母或者數字。

# encoding=utf-8
import base64
# 明文字符串
plaintext_str = 'abcdef'
# 實例化base64對象,加密操作
obj = base64.b64encode(plaintext_str.encode())
# 獲取解密後結果
plaintext_result =obj.decode()
print('加密後:%s' %plaintext_result)
# 解密
ciphertext_str = base64.b64decode(plaintext_result)
ciphertext_result = ciphertext_str.decode()
print('解密後:%s' %ciphertext_result)
"""
執行結果:
加密後:YWJjZGVm
解密後:abcdef
"""
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章