python文件&字符串MD5计算

def textMD5(source):
    m2 = hashlib.md5()
    m2.update(source.encode('utf-8'))
    return m2.hexdigest()


def fileMD5(file_path):
    md5_l = hashlib.md5()
    with open(file_path, mode="rb") as f:
        by = f.read()
    md5_l.update(by)
    return md5_l.hexdigest()


def getSHA1(res: str):
    """
    使用sha1加密算法,返回str加密后的字符串
    """
    sha = hashlib.sha1(res.encode('utf-8'))
    encrypts = sha.hexdigest()
    return encrypts

你可能感兴趣的:(Python,python)