zoukankan      html  css  js  c++  java
  • 使用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()

     运行结果:

    *** Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win32. ***
    >>> 
    *** Remote Interpreter Reinitialized  ***
    >>> 
    b'Copyright (c) 2012 Doucube Inc. All rights reserved.'
    b'Q29weXJpZ2h0IChjKSAyMDEyIERvdWN1YmUgSW5jLiBBbGwgcmlnaHRzIHJlc2VydmVkLg=='
    Q29weXJpZ2h0IChjKSAyMDEyIERvdWN1YmUgSW5jLiBBbGwgcmlnaHRzIHJlc2VydmVkLg==
    Copyright (c) 2012 Doucube Inc. All rights reserved.
    >>> 

    精简版

    import base64
    
    print(base64.b64decode(b'Q29weXJpZ2h0IChjKSAyMDEyIERvdWN1YmUgSW5jLiBBbGwgcmlnaHRzIHJlc2VydmVkLg==').decode())
  • 相关阅读:
    ant
    Java中的值传递和引用传递
    待解决的问题
    Ant生成文件解析
    JUnit初学
    遍历枚举
    2013年5月阅读链接
    《C Primer Plus》阅读笔记(3)
    《C Primer Plus》阅读笔记(2)
    《C Primer Plus》阅读笔记(4)
  • 原文地址:https://www.cnblogs.com/lanzhi/p/6468386.html
Copyright © 2011-2022 走看看