首页 > 编程 > Python > 正文

Python加密方法小结【md5,base64,sha1】

2019-11-25 16:01:23
字体:
来源:转载
供稿:网友

本文实例总结了python加密方法。分享给大家供大家参考,具体如下:

MD5加密:

def md5(str):  import hashlib  m = hashlib.md5()  m.update(str)  return m.hexdigest()

base64加密:

import base64s = '我是字符串'a = base64.b64encode(s)print aprint base64.b64decode(a)

输出结果:

ztLKx9fWt/u0rg==我是字符串

sha1加密:

需要导入hashlib 模块:

import hashlibdef str_encrypt(str):  """  使用sha1加密算法,返回str加密后的字符串  """  sha = hashlib.sha1(str)  encrypts = sha.hexdigest()  return encrypts

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

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

MD5在线加密工具:
http://tools.VeVB.COm/password/CreateMD5Password

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

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

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

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python加密解密算法与技巧总结》、《Python编码操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表