#!/usr/bin/env python
# -*- coding=utf-8 -*-import hashlib# hash:哈希算法,结果是内存地址
# print(hash('123')) #每次都不一样'''
hashlib模块,与加密相关,被称作 摘要算法
什么是摘要算法呢?摘要算法又称哈希算法、散列算法。它通过一个函数,把任意长度的数据转换为一个长度固定的数据串(通常用16进制的字符串表示)。1、是一堆算法的合集,包含很多算法(加密的)2、hashlib的过程:将字符串--->数字的过程3、在不同的电脑上,hashlib对相同的字符串转化成的数字相同
应用场景:密文(密码):将密码用算法加密放置到数据库,每次取出验证文件的校验
分类:md5:加密算法,常用算法,可以满足一般的常用的需求sha:加密算法,级别高一些,数字越大级别越高,加密的效率越低,越安全# ---------- md5
s1 = '12343254'
ret = hashlib.md5()  # 创建一个md5对象
ret.update(s1.encode('utf-8')) # 调用此update方法对参数进行加密 bytes类型
print(ret.hexdigest())  # 得到加密后的结果 定长# 无论多少数据,加密后的结果都是定长的
# 同一个数据,但会的md5值相同
''''''
有一些黑客,将常用的密码与对应的md5值放到一个库中,然后进行撞库
解决办法:加盐s2 = '12345'
ret = hashlib.md5('@$1*(^&@^2wqe'.encode('utf-8')) # 盐 - @$1*(^&@^2wqe
ret.update(s2.encode('utf-8'))
print(ret.hexdigest())
''''''
#弊端:黑客如果盗取了固定盐。。。。# 改进:变成随机盐 但是不能太随机,到时候不好匹配
# 账号密码:将账号或者各种变形 设置成随机盐
username = 'alex'
password = '12345'
ret = hashlib.md5(username[::-1].encode('utf-8'))
ret.update(password.encode('utf-8'))
print(ret.hexdigest())
'''
'''
# --------------sha系列
# sha1 与 md5 级别相同,但是 sha1 比 md5 更安全一些
ret = hashlib.sha1()
ret.update('123456'.encode('utf-8'))
print(ret.hexdigest())# sha512 级别最高,效率低,安全性最大
ret = hashlib.sha512()
ret.update('1234'.encode('utf-8'))
print(ret.hexdigest())
''''''
# ------------ 文件的校验
# 对于小文件可以,但是超大的文件内存受不了
# 通过校验前后文件编码过后的内容,可以查看文件有没有丢失def func(file_name):with open(file_name,mode='rb') as f1:ret = hashlib.md5()ret.update(f1.read())return ret.hexdigest()
print(func('hash_exec'))
'''
'''
# 校验的时候也可以分段校验
# 分段的时候切记里面的任何一个字符都不要落下
s1 = 'I am 旭哥, 都别惹我.... 不服你试试'
ret = hashlib.md5()
ret.update(s1.encode('utf-8'))
print(ret.hexdigest())  # 15f614e4f03312320cc5cf83c8b2706fs1 = 'I am 旭哥, 都别惹我.... 不服你试试'
ret = hashlib.md5()
ret.update('I am'.encode('utf-8'))
ret.update(' 旭哥, '.encode('utf-8'))
ret.update('都别惹我....'.encode('utf-8'))
ret.update(' 不服你试试'.encode('utf-8'))
print(ret.hexdigest())  # 15f614e4f03312320cc5cf83c8b2706f
'''
#大文件 - 一次校验一部分
def func(file_name):with open(file_name,'rb') as f1:ret = hashlib.md5()while True:content = f1.read(1024)if content: # 检验文件内容是否为空
                ret.update(content)else:breakreturn ret.hexdigest()

hashlib

#!/usr/bin/env python
# -*- coding=utf-8 -*-
# 配置文件:放置一些常用的变量,路径.
# 帮助你操作(创建,增,删,改,查)一个配置文件import configparser'''
# 创建一个配置文件
config = configparser.ConfigParser()
config["DEFAULT"] = {'ServerAliveInterval': '45','Compression': 'yes','CompressionLevel': '9','ForwardX11':'yes'}
config['bitbucket.org'] = {'User':'hg'}
config['topsecret.server.com'] = {'Host Port':'50022','ForwardX11':'no'}
with open('配置文件.ini','w') as configfile:config.write(configfile)
''''''
#基于字典形式,查找文件内容
config = configparser.ConfigParser()
config.read('配置文件.ini')
print(config.sections()) #没有DEFAULT,它是特殊的,可以看做一个全局的。
print('111'in config) # False 判断节名是否在配置文件中#对配置文件中的节对应的项,取值
print(config['bitbucket.org']['user']) # hg
print(config['bitbucket.org']) # <Section: bitbucket.org> 可迭代对象for key in config['bitbucket.org']:print(key) #注意:有default会默认default里面节的值print(config.options('bitbucket.org')) #找到default和bitbucket.org下的键
print(config.items('bitbucket.org')) #找到default和bitbucket.org下的键值对print(config.get('bitbucket.org','compression')) #yes 判断节点和项是否匹配'''#增删改
config = configparser.ConfigParser()
config.read('配置文件.ini')
config.add_section('alex')
config.remove_section('bitbucket.org')
config.remove_option('topsecret.server.com',"forwardx11")config.set('alex','k1','w')
config.write(open('配置文件2.ini','w'))

配置文件

#!/usr/bin/env python
# -*- coding=utf-8 -*-
# 配置文件:放置一些常用的变量,路径.
# 帮助你操作(创建,增,删,改,查)一个配置文件import configparser'''
# 创建一个配置文件
config = configparser.ConfigParser()
config["DEFAULT"] = {'ServerAliveInterval': '45','Compression': 'yes','CompressionLevel': '9','ForwardX11':'yes'}
config['bitbucket.org'] = {'User':'hg'}
config['topsecret.server.com'] = {'Host Port':'50022','ForwardX11':'no'}
with open('配置文件.ini','w') as configfile:config.write(configfile)
''''''
#基于字典形式,查找文件内容
config = configparser.ConfigParser()
config.read('配置文件.ini')
print(config.sections()) #没有DEFAULT,它是特殊的,可以看做一个全局的。
print('111'in config) # False 判断节名是否在配置文件中#对配置文件中的节对应的项,取值
print(config['bitbucket.org']['user']) # hg
print(config['bitbucket.org']) # <Section: bitbucket.org> 可迭代对象for key in config['bitbucket.org']:print(key) #注意:有default会默认default里面节的值print(config.options('bitbucket.org')) #找到default和bitbucket.org下的键
print(config.items('bitbucket.org')) #找到default和bitbucket.org下的键值对print(config.get('bitbucket.org','compression')) #yes 判断节点和项是否匹配'''#增删改
config = configparser.ConfigParser()
config.read('配置文件.ini')
config.add_section('alex')
config.remove_section('bitbucket.org')
config.remove_option('topsecret.server.com',"forwardx11")config.set('alex','k1','w')
config.write(open('配置文件2.ini','w'))

logging—低配版

转载于:https://www.cnblogs.com/liangying666/p/9282362.html

hashlib\logging\configparser相关推荐

  1. request,logging,ConfigParser——接口框架

    做一个将参数和用例分开放置,并且输出log的接口测试框架 我的框架如下所示 Log文件用来设置log输出文件,需要时可以在用例内调用输出,config用来填写一切需要的参数信息,jiekou_post ...

  2. python websocket例程_python 实现websocket

    #!/usr/bin python#-*- coding:UTF-8 -*- importredisimporttime, threading, sched, json, socket, base64 ...

  3. 知识点总结(基础篇)

    知识点总结1 PEP8 规范 每一级缩进使用4个空格. 空格是首选的缩进方式. 行限制的最大字符数为79 使用下划线分隔的小写字母 类名一般使用首字母大写的约定 异常名后面加上"Error& ...

  4. sql 超时时间已到.在操作完成之前超时时间已过或服务器未响应.,sqlserver Timeout 时间已到。在操作完成之前超时时间已过或服务器未响应...

    Linux 磁盘挂载和mount共享 针对Linux服务器的磁盘挂载mount和共享做简单操作说明: 1.  查看已使用的磁盘情况 df –h 2.  查看所有磁盘 fdisk –l 3.  查看指定 ...

  5. scrapy使用item,pipeline爬取数据,并且上传图片到oss

    Scrapy原理图 首先是要理解scrapy的运作原理是什么.这里不做解释,网上有很多资源可以理解. 声明item对象 明确了需要爬取哪些字段,就现在items.py里面定义字段 import scr ...

  6. Python基础常见面试题总结

    文章目录 基础知识题 看程序写结果题 编程题 以下是总结的一些常见的Python基础面试题,帮助大家回顾基础知识,了解面试套路.会一直保持更新状态. PS:加粗为需要注意的点. 基础知识题 1.深拷贝 ...

  7. 自动邮件发送(群发,加密等)

    使用Python自动发送邮件(群发,加密等) 在工作中很多公司没有购买专业的OA系统,发工资条,发通知,有时很不方便,要么专人做这个事,一个一个发 ,太麻烦,耗费很多工时.这个程序只需要整理发送信息的 ...

  8. python基础题目大全,测试你的水平,巩固知识(含答案) 1

    前言:很多时候跟着书和不系统的视频网站学习,会发现没有目标,学了很多却不知道自己到底能够做出什么成绩.要有一个清晰的职业学习规划,学习过程中会遇到很多问题,但是你跟着我一起学习,相信效果还是不错的. ...

  9. hashlib摘要算法模块,logging日志,configparser配置文件模块

    一.hashlib模块(摘要算法模块) 1.算法介绍 Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 什么是摘要算法呢? 摘要算法又称哈希算法.散列算法.它通过一个函数,把 ...

最新文章

  1. TFS数据迁移之sync_by_blk
  2. 【struts2+spring+hibernate】ssh框架整合开发
  3. Battlestation Operational HDU 6134
  4. Linux采用服务器网址,Linux实现https方式访问站点
  5. tensorflow2.1GPU版本(Windows+conda)的安装过程小结
  6. Windows创建自动化任务
  7. 2021大厂Java面试真题(分布式 )
  8. BOM详解(整个BOM架构体系)
  9. CodeSmith(C#)简单示例及相关小知识
  10. ETF基金定投策略回测分析
  11. 阿里龙蜥centos8.4 postgis 源码安装
  12. 医疗器械分销系统开发|分销商是怎么招募的?
  13. 同样是90后别人家的孩子已经是年薪百万算法工程师,而你呢?
  14. 关于SMTP邮件无法发送到 SMTP服务器,传输错误代码为 0x80040217
  15. 基于UE -Traffic_ SINR – Statistics — 手机在线视频流量对业务速率、小区容量影响分析
  16. java编写游戏_java编写小游戏-大球吃小球
  17. 爆破专栏丨Spring系列教程解决Spring Security环境中的跨域问题
  18. 爱普生打印机怎么安装使用
  19. 计算机思维 第7章
  20. Pointet++ Tutorial

热门文章

  1. 通过案例对SparkStreaming透彻理解-3
  2. Maven系列二setting.xml 配置详解
  3. 使用date命令,进行时间戳和日期时间的互转
  4. linux飞信机器人的安装fetion
  5. 无需编码创建app--应用之星制作app教程
  6. 【做事必须搞清10个顺序】
  7. 【Laro】- About Game Engine
  8. Lucene学习之——停用词
  9. JavaFX 架构与框架 (译)
  10. linux内核的反复--一切都是过程