title: python敏感信息加密
subtitle: base64
date: 2020-04-28
author: NSX
catalog: true
tags:
- Python
- 技术
python敏感信息加密
base64加密
import base64
"""
AskData的标准权限管理接口
测试环境:http://10.231.135.146:8060/auth
Request参数:
{}
"""
def jiami(xx):
unkownPassword=base64.b64encode(bytes(xx,'utf-8'))
print("加密后:"+str(unkownPassword,'utf-8'))
def jiemi(xx):
kownPassword=str(base64.b64decode(xx),'utf-8')
print('解密后:'+kownPassword)
cfg = ConfigParser()
cfg.read("config.ini", encoding="utf-8")
server = cfg["server67"]
username = base64.b64decode(b"%s" % server.get("user").encode()).decode("utf-8")
password = base64.b64decode(b"%s" % server.get("passwd").encode()).decode("utf-8")
pool = PooledDB(
creator=pymysql,
host=DB_CONFIG.get("host"),
port=DB_CONFIG.getint("port"),
user=DB_CONFIG.get("user"),
password=DB_CONFIG.get("passwd"),
db=DB_CONFIG.get("db"),
charset="utf8",
mincached=1, # 启动时开启的闲置连接数量
maxcached=3, # 连接池中允许的闲置的最多连接数量
maxconnections=5, # 创建连接池的最大数量
blocking=True, # 设置在连接池达到最大数量时的行为
maxusage=0, # 单个连接的最大允许复用次数(缺省值 0 或 False 代表不限制的复用)
)
self.db = pool.connection() # 获取链接池中的mysql链接
db = pymysql.connect(
host=DB_CONFIG.get("host"),
port=DB_CONFIG.getint("port"),
user=DB_CONFIG.get("user"),
passwd=DB_CONFIG.get("passwd"),
db=DB_CONFIG.get("db"),
charset="utf8",
# cursorclass=pymysql.cursors.DictCursor, # 以字典形式返回查询记录
)
# db.autocommit(1) # 执行完SQL语句后, 自动提交到真正的数据库(慎用)
print("数据库连接成功~~~~~~~")