zoukankan      html  css  js  c++  java
  • hashlib模块

    一、什么是哈希(hash)

    hash一类算法,该算法接受传入的内容,经过运算得到一串hash值 hash值的特点: I 只要传入的内容一样,得到的hash值必然一样 II 不能由hash值返解成内容 III 不管传入的内容有多大,只要使用的hash算法不变,得到的hash值长度是一定

    二、hash的用途

    用途1:特点II用于密码密文传输与验证 用途2:特点I、III用于文件完整性校验

    三、hash模块的使用

    import hashlib

    m=hashlib.md5()
    m.update('hello'.encode('utf-8'))
    m.update('world'.encode('utf-8'))
    res=m.hexdigest() # 'helloworld'
    print(res) # fc5e038d38a57032085441e7fe7010b0

    # 加密操作

    可以分批传入

    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) # fc5e038d38a57032085441e7fe7010b0

    密码加盐

    import hashlib

    m=hashlib.md5()

    m.update('天王'.encode('utf-8'))
    m.update('alex3714'.encode('utf-8'))
    m.update('盖地虎'.encode('utf-8'))
    print(m.hexdigest())

    模拟撞库(破解密码)

    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
          
    # ps:密码加盐可以提高撞库成本

  • 相关阅读:
    python笔记之re模块学习
    python笔记之面向对象
    C# 静态类和非静态类(实例类)
    占位符的使用
    数据类型和数据类型转换
    win7 安装 memcached
    php 汉字转换成拼音
    apache window环境下本地配置虚拟主机
    在浏览器输入一个网址到得到页面的过程
    浅谈线程池ThreadPoolExecutor核心参数
  • 原文地址:https://www.cnblogs.com/bailongcaptain/p/12608730.html
Copyright © 2011-2022 走看看