本文实例讲述了Python使用MD5加密算法对字符串进行加密操作。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# encoding: utf-8
from __future__ import division
import time
import sys
reload (sys)
time1 = time.time()
sys.setdefaultencoding( 'utf-8' )
#######Md5实现方式1
import hashlib
# 创建md5对象
hl = hashlib.md5()
password = "gxbdb684f1b8cfdf046744ea96d9fce48469fbac305dc6aa0d6operator_pro1520391961274j4102412y5210ying"
hl.update(password)
print (password)
sign = hl.hexdigest()
print sign
##########MD5实现方式2
import hashlib
md5 = hashlib.md5(password.encode( 'utf-8' )).hexdigest()
print (md5)
|
输出结果:
gxbdb684f1b8cfdf046744ea96d9fce48469fbac305dc6aa0d6operator_pro1520391961274j4102412y5210ying
856b690e42eb4ce5af4c3e5be9a97bb5
856b690e42eb4ce5af4c3e5be9a97bb5
Process finished with exit code 0
希望本文所述对大家Python程序设计有所帮助。
原文链接:https://blog.csdn.net/u013421629/article/details/79468420