Python hashlib模块与subprocess模块使用详细介绍
作者:Python热爱者 时间:2021-09-25 18:06:47
1、什么是哈希hash
hash一类算法,该算法接受传入的内容,经过运算得到一串hash值
hash值的特点:
只要传入的内容一样,得到的hash值必然一样
不能由hash值返解成内容
不管传入的内容有多大,只要使用的hash算法不变,得到的hash值长度是一定
2、hash的用途
用途1:特点II用于密码密文传输与验证
用途2:特点I、III用于文件完整性校验
3、如何用
import hashlib
m=hashlib.md5()
m.update('hello'.encode('utf-8'))
m.update('world'.encode('utf-8'))
res=m.hexdigest() # 'helloworld'
print(res)
m1=hashlib.md5('he'.encode('utf-8'))
m1.update('llo'.encode('utf-8'))
m1.update('w'.encode('utf-8'))
m1.update('orld'.encode('utf-8'))
res=m1.hexdigest()# 'helloworld'
print(res)
模拟撞库
cryptograph='aee949757a2e698417463d47acac93df'
import hashlib
# 制作密码字段
passwds=[
'alex3714',
'alex1313',
'alex94139413',
'alex123456',
'123456alex',
'a123lex',
]
dic={}
for p in passwds:
res=hashlib.md5(p.encode('utf-8'))
dic[p]=res.hexdigest()
# 模拟撞库得到密码
for k,v in dic.items():
if v == cryptograph:
print('撞库成功,明文密码是:%s' %k)
break
提升撞库的成本=>密码加盐
import hashlib
m=hashlib.md5()
m.update('天王'.encode('utf-8'))
m.update('alex3714'.encode('utf-8'))
m.update('盖地虎'.encode('utf-8'))
print(m.hexdigest())
4、subprocess模块
subprocess使用当前系统默认编码,得到结果为bytes类型,在windows下需要用gbk解码
import subprocess
obj=subprocess.Popen('echo 123 ; ls / ; ls /root',shell=True,
stdout=subprocess.PIPE, #正确的管道
stderr=subprocess.PIPE,#错误的管道
)
# print(obj)
# res=obj.stdout.read()
# print(res.decode('utf-8'))
err_res=obj.stderr.read()
print(err_res.decode('gbk')) # windows下需要用gbk解码mac、linux用utf-8解码
来源:https://blog.csdn.net/qdPython/article/details/127013075
标签:Python,hashlib,subprocess,模块
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
PHP比你想象的好得多
2023-11-20 09:33:30
美工自我培养的几点经验总结
2009-11-19 12:57:00
![](https://img.aspxhome.com/file/UploadPic/200911/19/f2player-18s.png)
如何将自己的python库打包成wheel文件并上传到pypi
2022-03-20 06:13:40
![](https://img.aspxhome.com/file/2023/9/78669_0s.png)
python的help函数如何使用
2023-12-21 10:46:48
快速解决SQL server 2005孤立用户问题
2009-01-04 14:02:00
Python面向对象程序设计中类的定义、实例化、封装及私有变量/方法详解
2021-10-15 16:14:07
fckeditor编辑器在php中的配置方法
2023-10-14 14:26:52
关闭窗口时保存数据的办法
2009-02-19 13:39:00
Python数学建模库StatsModels统计回归简介初识
2021-05-05 04:57:02
pycharm远程调试openstack的图文教程
2021-10-31 06:37:56
![](https://img.aspxhome.com/file/2023/6/87966_0s.png)
Python设计模式之观察者模式简单示例
2023-07-12 04:36:06
![](https://img.aspxhome.com/file/2023/3/84063_0s.png)
python并发编程多进程 互斥锁原理解析
2023-04-07 04:06:34
asp使用ServerVariables集合
2008-02-27 13:22:00
![](https://img.aspxhome.com/file/UploadPic/20082/27/2008227132759154s.jpg)
rs.open sql,conn,1,1与rs.open sql,conn,1.3还有rs.open sql,conn,3,2区别
2011-02-24 10:49:00
解决pycharm下载库时出现Failed to install package的问题
2021-07-30 14:15:49
![](https://img.aspxhome.com/file/2023/0/72890_0s.png)
TensorFlow和Numpy矩阵操作中axis理解及axis=-1的解释
2021-02-14 05:59:09
![](https://img.aspxhome.com/file/2023/3/91933_0s.png)
Python使用贪婪算法解决问题
2022-04-13 10:23:14
免费手机号码归属地API查询接口和PHP使用实例分享
2023-10-31 08:06:37
Python实现"验证回文串"的几种方法
2021-03-28 15:48:57
使用PHP批量生成随机用户名
2023-07-22 13:10:10