1. 程式人生 > >hashlib 文件校驗,MD5動態加鹽返回加密後字符

hashlib 文件校驗,MD5動態加鹽返回加密後字符

str span 文件 date code return tro mod update

hashlib 文件校驗

# for循環校驗
import hashlib
def check_md5(file):
    ret = hashlib.md5()
    with open(file, mode=rb) as f1:
        for line in f1:
            ret.update(line)
        return ret.hexdigest()


print(check_md5(rock1))
print(check_md5(rock))
print(check_md5(rock1) == check_md5(rock
)) # while循環每次讀取1024字節校驗 import hashlib def check_md5(file): ret = hashlib.md5() with open(file, mode=rb) as f1: while 1: content = f1.read(1024) if content: ret.update(content) else: break return ret.hexdigest()
print(check_md5(rock1)) print(check_md5(rock)) print(check_md5(rock1) == check_md5(rock))

用戶名動態加鹽校驗

import hashlib


def check_md5(s=‘‘):
    # ret = hashlib.md5(‘w‘.encode(‘utf-8‘))
    # print(s[::-2])
    ret = hashlib.md5()
    ret.update(s[::-2].encode(utf-8))
    ret.update(s.encode(
utf-8)) return ret.hexdigest() print(check_md5(146123)) print(check_md5(146123)) print(check_md5(rock) == check_md

hashlib 文件校驗,MD5動態加鹽返回加密後字符