網(wǎng)站首頁 編程語言 正文
1、什么是哈希hash
hash一類算法,該算法接受傳入的內(nèi)容,經(jīng)過運(yùn)算得到一串hash值
hash值的特點(diǎn):
- 只要傳入的內(nèi)容一樣,得到的hash值必然一樣
- 不能由hash值返解成內(nèi)容
- 不管傳入的內(nèi)容有多大,只要使用的hash算法不變,得到的hash值長度是一定
2、hash的用途
用途1:特點(diǎn)II用于密碼密文傳輸與驗(yàn)證
用途2:特點(diǎn)I、III用于文件完整性校驗(yàn)
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使用當(dāng)前系統(tǒng)默認(rèn)編碼,得到結(jié)果為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
相關(guān)推薦
- 2024-01-29 Spring 的存儲和獲取Bean
- 2022-07-14 設(shè)置Redis最大占用內(nèi)存的實(shí)現(xiàn)_Redis
- 2022-10-03 Go?Excelize?API源碼閱讀Close及NewSheet方法示例解析_Golang
- 2022-09-08 python如何獲取tensor()數(shù)據(jù)類型中的值_python
- 2022-08-18 python高階函數(shù)使用教程示例_python
- 2022-09-22 vite alias配置路徑地址別名
- 2022-04-11 C++?std::initializer_list?實(shí)現(xiàn)原理解析及遇到問題_C 語言
- 2022-05-25 python?序列去重并保持原始順序操作_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支