把寫內容過程中常用的內容段記錄起來,下面的資料是關於使用python3的base64編解碼實現字符串的簡易加密解密的內容。
import base64
copyright = 'Copyright (c) 2012 Doucube Inc. All rights reserved.'
def main():
#轉成bytes string
bytesString = copyright.encode(encoding="utf-8")
print(bytesString)
#base64 編碼
encodestr = base64.b64encode(bytesString)
print(encodestr)
print(encodestr.decode())
#解碼
decodestr = base64.b64decode(encodestr)
print(decodestr.decode())
if __name__ == '__main__':
main()
輸出結果
>>>
>>>
b'Copyright (c) 2012 Doucube Inc. All rights reserved.'
b'Q29weXJpZ2h0IChjKSAyMDEyIERvdWN1YmUgSW5jLiBBbGwgcmlnaHRzIHJlc2VydmVkLg=='
Q29weXJpZ2h0IChjKSAyMDEyIERvdWN1YmUgSW5jLiBBbGwgcmlnaHRzIHJlc2VydmVkLg==
Copyright (c) 2012 Doucube Inc. All rights reserved.
>>>