企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] <br> ### hashlib 模块介绍 用于加密相关的操作,3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法 ### 各加密算法实例 #### MD5 加密 ```cmd >>> import hashlib >>> >>> hash=hashlib.md5() >>> hash.update("Milton".encode()) >>> hash.hexdigest() '7c6e8d16a121df9be3e30701e417d11b' ``` #### SHA1 加密 ```cmd >>> import hashlib >>> >>> hash=hashlib.sha1() >>> hash.update("Milton".encode()) >>> hash.hexdigest() 'dbcf6d6ba1c030decacef981a87a1ccc1e27fe38' ``` #### SHA256 加密 ```cmd >>> import hashlib >>> >>> hash=hashlib.sha256() >>> hash.update("Milton".encode()) >>> hash.hexdigest() '8856d174978691a21f99f822bba5c8ae7fe1d25678f0e758d7be35f30bd79088' ``` #### SHA384 加密 ```cmd >>> import hashlib >>> >>> hash=hashlib.sha384() >>> hash.update("Milton".encode()) >>> hash.hexdigest() '7449e979b3c964ea57e55b0703ce5b685744f8480d036a5bb020c7e9c7644a43c42358d68a23d4765797ede4b1e339b3' ``` #### SHA512 加密 ```cmd >>> import hashlib >>> >>> hash=hashlib.sha512() >>> hash.update("Milton".encode()) >>> hash.hexdigest() '2c98694170af254719679831e8f21fb0e982c27f8c4dc4828b6373678d011faab01fb70673d2d4f068b3c0255f7bdd62c61408e4db4819481e962b6 0cb099562' >>> ``` <hr style="margin-top:100px"> :-: ![](https://box.kancloud.cn/2ff0bc02ec938fef8b6dd7b7f16ee11d_258x258.jpg) ***微信扫一扫,关注“python测试开发圈”,了解更多测试教程!***