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

  

最新文章

  1. 接口与继承ppt作业
  2. 自适应UITableView的Cell高度问题
  3. PHP 定界符使用
  4. 更改Android Studio的主题背景
  5. smarty基本语法
  6. pkg-config问题:
  7. [转]iOS/iphone开发如何为苹果开发者帐号APPID续费
  8. Who is the best at Dataset X?
  9. 教程-Supports判断接口(Instance)是否支持
  10. python----特性001
  11. Java-----instanceof、isInstance、isAssignableFrom
  12. 网络编程API-上 (基本API)
  13. rpm命令说明
  14. 【Spring】使用Spring和AMQP发送接收消息(中)
  15. [mark] first shellcode
  16. html5 javascript 小型计算器
  17. 在C++中定义常量
  18. PAT 甲级 1083 List Grades (25 分)
  19. Android 里的数据储存
  20. c#.net基础

热门文章

  1. JS 设计模式一 -- 原型模式
  2. OracleSql语句学习(四)
  3. DOTween的Sequence图例说明
  4. mybatis 使用resultMap实现表间关联
  5. oracle创建表空间等相关语句
  6. Microsoft Visual Studio Tools for AI
  7. Fixing “Did you mean to run dotnet SDK commands?” error when running dotnet –version
  8. 字符串格式的方法%s、format和python3.6新特性f-string和类型注解
  9. Linux shell if判断语句
  10. Django+Vue打造购物网站(八)