網站首頁 編程語言 正文
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
相關推薦
- 2022-02-22 Linux系統下根目錄擴容介紹_Linux
- 2022-06-22 利用Docker?運行?python?簡單程序_docker
- 2022-07-13 Zookeeper集群 + Kafka集群
- 2022-08-18 C#開發Windows?UWP系列之對話框MessageDialog和ContentDialog_C
- 2022-04-11 android?ViewPager實現一個無限輪播圖_Android
- 2022-05-09 React中的axios模塊及使用方法_React
- 2023-01-17 FFmpeg實戰之利用ffplay實現自定義輸入流播放_C 語言
- 2022-06-14 Golang使用ini庫讀取配置詳情_Golang
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支