title: python敏感信息加密
subtitle: base64
date: 2020-04-28
author: NSX
catalog: true
tags:

  • Python
  • 技术

python敏感信息加密

base64加密

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