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

    hashlib模块是一个提供摘要算法的模块

    对相同的字符串使用同一个算法进行摘要,所得到的值总是不变的

    使用不同的算法进行摘要,得到的值应该是不同的

    一般用md5,密码的密文存储、文件的一致性检验

    为防止撞库 ,对md5加盐

    #静态加盐
    import
    hashlib md5 = hashlib.md5() md5 = hashlib.md5(bytes("slat",encoding="utf-8")) #加盐后的写法 “slat” 为随意字符串 md5.update(b"abc123") print(md5.hexdigest())

    #动态加盐

    #未完成
    s1 = "" def file1_md5(): with open("test.bak","r",encoding="utf-8") as fr: for line in fr.read(1024): md5 = hashlib.md5() md5.update(line.encode("utf-8")) yield md5.hexdigest() g1 = file1_md5() for i in g1: s1 = s1 + i print(s1) s2 = "" def file2_md5(): with open("test.bak","rb") as fr: for line in fr: line = line.strip() md5 = hashlib.md5() md5.update(line) yield md5.hexdigest() g2 = file2_md5() for i in g2: s2 = s2 + i print(s2) print(s1 == s2)
  • 相关阅读:
    列式数据库
    Subway POJ
    操作系统知识汇总
    Linux工具指南
    常用数据结构
    bzoj1257: [CQOI2007]余数之和 整除分块
    HDU
    hdu1693 Eat the Trees 插头dp
    HDU
    poj2411 轮廓线dp裸题
  • 原文地址:https://www.cnblogs.com/superniao/p/10070772.html
Copyright © 2011-2022 走看看