使用python3的base64編解碼實現字符串的簡易加密解密的代碼

把寫內容過程中常用的內容段記錄起來,下面的資料是關於使用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.
>>>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章