python_base64和encode函数


对于python来说,base64加密与解密,有一个专门的函数供我们使用:

base64库

加密为:base64.b64encode()

解密为:base64.b64decode()

具体例子:

import base64            #导入base64库
s='最强近战单位SCV'
b=bytes(s,'utf-8')      #将s的类型转化为bytes类型
c=base64.b64encode(b)   #base64加密  
print(c)

1

解密代码:

import base64                       #导入base64库
s='5pyA5by66L+R5oiY5Y2V5L2NU0NW'    
b=bytes(s,'utf-8')                  
c=base64.b64decode(b)               #解密
print(c)                            #直接输出c
print( )
print(c.decode())                   #将c按照字符串输出

1

上面提到了encode函数:

str_1="翔鹤太太"
str_2= "shoukaku&ladylex"
print(str_1.encode('utf-8'))
print(str_2.encode('utf-8'))

1


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM