Python使用MD5加密算法对字符串进行加密操作示例

冬天地上扑的是雪,厚厚的,软软的;房上落的是雪,白皑皑的,又松又软;树上盖的是雪,积雪把树枝压弯了腰。太阳照在雪山上,发出耀眼的光芒。

本文实例讲述了Python使用MD5加密算法对字符串进行加密操作。分享给大家供大家参考,具体如下:

# 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

PS:关于加密解密感兴趣的朋友还可以参考本站在线工具:

文字在线加密解密工具(包含AES、DES、RC4等):
http://tools.haodaima.com/password/txt_encode

MD5在线加密工具:
http://tools.haodaima.com/password/CreateMD5Password

在线散列/哈希算法加密工具:
http://tools.haodaima.com/password/hash_encrypt

在线MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160加密工具:
http://tools.haodaima.com/password/hash_md5_sha

在线sha1/sha224/sha256/sha384/sha512加密工具:
http://tools.haodaima.com/password/sha_encode

希望本文所述对大家Python程序设计有所帮助。

以上就是Python使用MD5加密算法对字符串进行加密操作示例。高标准,精细化,零缺陷。更多关于Python使用MD5加密算法对字符串进行加密操作示例请关注haodaima.com其它相关文章!

您可能有感兴趣的文章
Python自动化运维-使用Python脚本监控华为AR路由器关键路由变化

Python自动化运维-netmiko模块设备自动发现

Python自动化运维—netmiko模块连接并配置华为交换机

Python自动化运维-利用Python-netmiko模块备份设备配置

Python自动化运维-Paramiko模块和堡垒机实战