【python】md5加密方法相关使用
2024-10-16 08:48:11
md5方法在hashlib库中,使用前需要先导入。它的主要方法为update,copy,以及转换为二进制,十六进制。
用法说明:
Help on HASH object: class HASH(builtins.object)
| A hash represents the object used to calculate a checksum of a
| string of information.
|
| Methods:
|
| update() -- updates the current digest with an additional string
| digest() -- return the current digest value
| hexdigest() -- return the current digest as a string of hexadecimal digits
| copy() -- return a copy of the current hash object
实例如下:
>>> from hashlib import md5
>>> e='lilip@email.com'
>>> print(e)
lilip@email.com
>>> e_encode=e.lower().encode('utf-8')
>>> print(e_encode)
b'lilip@email.com'
>>> e_md5=md5(e_encode)
>>> print(e_md5)
<md5 HASH object @ 0x0000000002961B20>
>>> e_hex=e_md5.hexdigest() #转换为十六进制
>>> print(e_hex)
d56e0ee2ffdd3c8e8f75219044e6b781
>>> e_digest=e_md5.digest() #转换为二进制
>>> print(e_digest)
b'\xd5n\x0e\xe2\xff\xdd<\x8e\x8fu!\x90D\xe6\xb7\x81'
>>> e_copy=e_md5.copy() #copy用法
>>> print(e_copy)
<md5 HASH object @ 0x0000000002961B48>
>>> print(e_md5)
<md5 HASH object @ 0x0000000002961B20>
>>> e_md5.update('test'.encode('utf-8')) #update用法
>>> print(e_md5)
<md5 HASH object @ 0x0000000002961B20>
>>> print(e_md5.hexdigest())
8b3b5ccd79b8a1c6aa50e40ad1e479b8
最新文章
- 接口与继承ppt作业
- 自适应UITableView的Cell高度问题
- PHP 定界符使用
- 更改Android Studio的主题背景
- smarty基本语法
- pkg-config问题:
- [转]iOS/iphone开发如何为苹果开发者帐号APPID续费
- Who is the best at Dataset X?
- 教程-Supports判断接口(Instance)是否支持
- python----特性001
- Java-----instanceof、isInstance、isAssignableFrom
- 网络编程API-上 (基本API)
- rpm命令说明
- 【Spring】使用Spring和AMQP发送接收消息(中)
- [mark] first shellcode
- html5 javascript 小型计算器
- 在C++中定义常量
- PAT 甲级 1083 List Grades (25 分)
- Android 里的数据储存
- c#.net基础
热门文章
- JS 设计模式一 -- 原型模式
- OracleSql语句学习(四)
- DOTween的Sequence图例说明
- mybatis 使用resultMap实现表间关联
- oracle创建表空间等相关语句
- Microsoft Visual Studio Tools for AI
- Fixing “Did you mean to run dotnet SDK commands?” error when running dotnet –version
- 字符串格式的方法%s、format和python3.6新特性f-string和类型注解
- Linux shell if判断语句
- Django+Vue打造购物网站(八)