实现原理:导入base64库
一、加密
import base64
# 加密
username = "admin"
base64_username = base64.b64encode(username.encode('utf-8')).decode()
print(base64_username)
password = "123"
base64_password = base64.b64encode(password.encode('utf-8')).decode()
print(base64_password)
运行结果:
Q1NETg==
MTIz
在线测试网址:https://www.uutils.com/enc/md5.htm
二、解密
import base64
# 加密
username = "CSDN"
base64_username = base64.b64encode(username.encode('utf-8')).decode()
print(base64_username)
password = "123"
base64_password = base64.b64encode(password.encode('utf-8')).decode()
print(base64_password)
# 解密
str1 = base64.b64decode(base64_username.encode('utf-8')).decode()
print(str1)