本文主要是介绍文本文件完整性判断-加密,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、定义
- 文件加密
二、实现
- 文件加密
import sys
import hashlibdef calculate_md5(fpath: str, chunk_size: int = 1024 * 1024) -> str:""" Calculates the MD5 checksum of a file located at the path specified by the fpath.Parameters----------fpath : strFile path.chunk_size : intSpecifies the size of the chunks of the file that are read.Returns-------strReturns MD5 checksum of a file located at the fpath."""if sys.version_info >= (3, 9):md5 = hashlib.md5(usedforsecurity=False)else:md5 = hashlib.md5()with open(fpath, "rb") as f:for chunk in iter(lambda: f.read(chunk_size), b""):md5.update(chunk)return md5.hexdigest()if __name__ == '__main__':res=calculate_md5(fpath="D:/cnki_1/neurai_project\dataset_load\CJDFTRIPLET/raw11/cjdf500k_9.csv")print(res)
这篇关于文本文件完整性判断-加密的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!