1.简述
加密解密基于base64库,无需再额外安装其他库
2.示例代码
import base64
def base64_encode(data):
message_bytes = data.encode('utf-8') # 将字符串转换为字节型
base64_bytes = base64.b64encode(message_bytes) # 进行加密
print(base64_bytes,type(base64_bytes),len(base64_bytes))
return base64_bytes
def base64_decode(data):
#base64_bytes = data.encode('utf-8')
message_bytes = base64.b64decode(data)
message = message_bytes.decode('utf-8')
return message
mm = "{'name': 'webAdmin', 'passwd': 'admin1,.'}"
nn = base64_encode(mm)
print(base64_decode(nn))
mmm = b'f8074c19c12f3945e371d3d6d79e6b96'
print(len(mmm))
print(base64_decode(mmm))