使用python实现md5加密

时间:2023-08-18 14:40:09 类型:python
字号:    

当我们需要进行数据加密时,一种常见的方式是使用哈希算法。其中,MD5算法是一种较为常见且流行的哈希算法,可以使用Python语言轻松实现。以下是使用Python实现MD5加密的完整攻略:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import hashlib
 
# 创建md5对象
md5 = hashlib.md5()
 
# 待加密字符串
= '你好'
 
# 更新md5对象
md5.update(s.encode('utf-8'))
 
# 获取加密结果
result = md5.hexdigest()
 
print(result)

打印结果:

1
6f8db599de986fab7a21625b7916589c


<